﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using System.Data;
using Dapper;
using Dapper.Contrib.Extensions;

namespace Topro.Web.Controllers
{
    using System.Text;
    using Topro.Db;
    using Topro.Entity;
    using Topro.Entity.Tables;
    using Topro.Enums;
    using Topro.Util;
    using Topro.Web.Query;
    using Topro.Web.Request;
    using Topro.Web.Response;

    /// <summary>
    /// 首页控制器
    /// </summary>
    public class HomeController : BaseController
    {
        #region 注入
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<HomeController> _logger;

        /// <summary>
        /// 数据接口
        /// </summary>
        private readonly IDb _db;

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        private readonly string _connectionStrings = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build()["ConnectionStrings:mysqlconnection"];

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        public HomeController(ILogger<HomeController> logger, IDb db)
        {
            _logger = logger;
            _db = db;
        }
        #endregion

        #region 首页
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            //var configPah = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build()["data:config"];
            //if(FileUtil.HasFile(configPah))
            //{
            //    var xml = FileUtil.loadFile(configPah);
            //    if(xml !=null)
            //    {
            //        var configs = SerializationUtil.XmlToList<Config>(xml, "ArrayOfConfig");

            //        var x = "";
            //    }
            //}

            //var dictionaryPah = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build()["data:dictionary"];
            //if (FileUtil.HasFile(dictionaryPah))
            //{
            //    var xml = FileUtil.loadFile(dictionaryPah);
            //    if (xml != null)
            //    {
            //        var dictionarys = SerializationUtil.XmlToList<Dictionary>(xml, "ArrayOfDictionary");

            //        var x = "";
            //    }
            //}

            //var iqsPah = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build()["Default:IQS"];
            //if (Directory.Exists(iqsPah))
            //{
            //    iqsPah += @"\iqs.xml";

            //    var xml = FileUtil.loadFile(iqsPah);
            //    if (xml != null)
            //    {
            //        var iqs = SerializationUtil.XmlToModel<IQS>(xml, "IQS");

            //        var x = "";
            //    }
            //}

            var response = new IQSResponse();
            //零包OR整包
            response.PostponedMaterialType = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(PostponedMaterialType));
            //延期材料
            response.PostponedMaterial = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(PostponedMaterialType));
            //公告
            var Infos = new List<InfoQueryResponse>();
            //所有班次生效
            var shiftNums = _db.DbConnection.Query<Info>("select * from info where Status=1 ORDER BY id DESC LIMIT 0,5 ").ToList();
            if (shiftNums != null && shiftNums.Any())
            {
                shiftNums.ForEach(item => {
                    Infos.Add(new InfoQueryResponse()
                    {
                        Id = item.Id,
                        Type = item.Type,
                        Value = item.Value,
                        Message = item.Message,
                    });
                });
            }

            ViewBag.Info = Infos;

            ViewBag.Ip = Ip;
            //ViewBag.UserName = UserName;
            return View(response);
        }
        #endregion

        #region 选择
        /// <summary>
        /// 选择
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Select(int type)
        {
            ViewBag.Type = type;
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns>PagedList<?></returns>
        [HttpGet]
        public IActionResult SelectQuery(DictionaryQuery query)
        {
            var dictionarys = GetDictionary();
            //索引
            var pageIndex = query.PageIndex <= 0 ? 0 : (query.PageIndex - 1) * query.PageSize;
            //列表
            var list = dictionarys.Where(c => c.Type == query.Type).Skip(pageIndex).Take(query.PageSize).ToList();
            var count = dictionarys.Where(c =>c.Type == query.Type).ToList().Count;

            return PartialView("_Query", new PagedList<Dictionary>()
            {
                TData = list,
                CurrentPageIndex = query.PageIndex,
                TotalCount = count
            });
        }
        #endregion

        #region 消息
        /// <summary>
        /// 选择
        /// </summary>
        /// <param name="equipmentCode"></param>
        /// <param name="staffNum"></param>
        /// <param name="shiftNum"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Info(string equipmentCode,string staffNum,string shiftNum)
        {
            ViewBag.equipmentCode = equipmentCode;
            ViewBag.staffNum = staffNum;
            ViewBag.shiftNum = shiftNum;

            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns>PagedList<?></returns>
        [HttpGet]
        public IActionResult InfoQuery(InfoQuery query)
        {
            var list = GetInfos(query);

            return PartialView("_InfoQuery", list);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public List<InfoQueryResponse> GetInfos(InfoQuery query)
        {
            var list = new List<InfoQueryResponse>();

            #region 机台编码
            if (!string.IsNullOrEmpty(query.EquipmentCode))
            {
                //所有班次生效
                var shiftNums = _db.DbConnection.Query<Info>("select * from info where Type=@Type And Value='0' And FIND_IN_SET(@EquipmentCode,Record)=0 And Status=1", new { Type = (int)InfoType.机器编码, EquipmentCode = query.EquipmentCode }).ToList();
                if (shiftNums != null && shiftNums.Any())
                {
                    shiftNums.ForEach(item => {
                        list.Add(new InfoQueryResponse()
                        {
                            Id = item.Id,
                            Type = item.Type,
                            Value = item.Value,
                            Message = item.Message,
                            Sign = query.EquipmentCode
                        });
                    });
                }
                //设定的员工
                var shiftNumOne = _db.DbConnection.Query<Info>("select * from info where Type=@Type And Value=@EquipmentCode AND FIND_IN_SET(@EquipmentCode,Record)=0 And Status=1", new { Type = (int)InfoType.机器编码, EquipmentCode = query.EquipmentCode }).FirstOrDefault();
                if (shiftNumOne != null)
                {
                    list.Add(new InfoQueryResponse()
                    {
                        Id = shiftNumOne.Id,
                        Type = shiftNumOne.Type,
                        Value = shiftNumOne.Value,
                        Message = shiftNumOne.Message,
                        Sign = query.EquipmentCode
                    });
                }
            }
            #endregion

            #region 员工号
            if (!string.IsNullOrEmpty(query.StaffNum))
            {
                //所有员工生效
                var staffNums = _db.DbConnection.Query<Info>("select * from info where Type=@Type And Value='0' And FIND_IN_SET(@StaffNum,Record)=0 And Status=1", new { Type = (int)InfoType.员工号, StaffNum = query.StaffNum }).ToList();
                if (staffNums != null && staffNums.Any())
                {
                    staffNums.ForEach(item => {
                        list.Add(new InfoQueryResponse()
                        {
                            Id = item.Id,
                            Type = item.Type,
                            Value = item.Value,
                            Message = item.Message,
                            Sign = query.StaffNum
                        });
                    });
                }
                //设定的员工
                var staffNumOne = _db.DbConnection.Query<Info>("select * from info where Type=@Type And Value=@StaffNum AND FIND_IN_SET(@StaffNum,Record)=0 And Status=1", new { Type = (int)InfoType.员工号, StaffNum = query.StaffNum }).FirstOrDefault();
                if (staffNumOne != null)
                {
                    list.Add(new InfoQueryResponse()
                    {
                        Id = staffNumOne.Id,
                        Type = staffNumOne.Type,
                        Value = staffNumOne.Value,
                        Message = staffNumOne.Message,
                        Sign = query.StaffNum
                    });
                }
            }
            #endregion

            #region 班次
            if (!string.IsNullOrEmpty(query.ShiftNum))
            {
                //所有班次生效
                var shiftNums = _db.DbConnection.Query<Info>("select * from info where Type=@Type And Value='0' And FIND_IN_SET(@ShiftNum,Record)=0 And Status=1", new { Type = (int)InfoType.班次, ShiftNum = query.ShiftNum }).ToList();
                if (shiftNums != null && shiftNums.Any())
                {
                    shiftNums.ForEach(item => {
                        list.Add(new InfoQueryResponse()
                        {
                            Id = item.Id,
                            Type = item.Type,
                            Value = item.Value,
                            Message = item.Message,
                            Sign = query.ShiftNum
                        });
                    });
                }
                //设定的员工
                var shiftNumOne = _db.DbConnection.Query<Info>("select * from info where Type=@Type And Value=@ShiftNum AND FIND_IN_SET(@ShiftNum,Record)=0 And Status=1", new { Type = (int)InfoType.班次, ShiftNum = query.ShiftNum }).FirstOrDefault();
                if (shiftNumOne != null)
                {
                    list.Add(new InfoQueryResponse()
                    {
                        Id = shiftNumOne.Id,
                        Type = shiftNumOne.Type,
                        Value = shiftNumOne.Value,
                        Message = shiftNumOne.Message,
                        Sign = query.ShiftNum
                    });
                }
            }
            #endregion

            return list;
        }

        /// <summary>
        /// 确认
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Confirm(ConfirmRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                //执行查询
                var info = _db.DbConnection.Query<Info>("select * from info where id=@id",new { id = request .Id}).FirstOrDefault();
                if(info==null)
                {
                    throw new Exception("记录不存在.");
                }

                var record = $"{info.Record},{request.Sign}";
                int result = _db.DbConnection.Execute("UPDATE info SET Record=@Record WHERE Id=@Id", new { Record = record, Id = info.Id });
                if (result <= 0)
                {
                    throw new Exception("更新失败");
                }

                response.Success = true;
                response.Message = "操作成功.";
            }
            catch(Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region 条码验证

        #region Lot 批号(上条码)
        /// <summary>
        /// Lot 批号(上条码)  string content,string equipmentCode,string staffNum,string shiftNum
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult LotBatch(LotBatchReqeust reqeust)
        {
            var response = new JResult<LotBatchResponse>()
            {
                Success = false
            };

            try
            {
                var data = new LotBatchResponse();

                if (string.IsNullOrEmpty(reqeust.LotBatch))
                {
                    throw new Exception("Lot 批号(上条码)不能为空.");
                }

                //材料
                var partNum = "";

                if (reqeust.LotBatch.IndexOf("|") > 0)
                {
                    var arr = reqeust.LotBatch.Split("|");

                    if (arr.Length < 3)
                    {
                        throw new Exception("Lot 批号(上条码)格式有误.");
                    }
                    //批号
                    data.LotBatch = arr[0];
                    //料号
                    data.PartNum = arr[1].ToUpper();
                    //叠合次数号
                    data.HeapNumber = arr[2].Substring(0, 1).Replace("8", "E");
                    //材料类型
                    data.MaterialType = "Cu_pp";
                    //长度数组
                    var Lengths = new List<int>() { 6, 7, 8 };
                    //长度验证
                    if (Lengths.Any(item => item == data.PartNum.Length))
                    {
                        partNum = data.PartNum.Substring(0, data.PartNum.Length - 1);
                    }
                    else
                    {
                        partNum = data.PartNum;
                    }
                }
                else if(reqeust.LotBatch.IndexOf("@") > 0)
                {
                    var arr = reqeust.LotBatch.Split("@");

                    if (arr.Length < 3)
                    {
                        throw new Exception("Lot 批号(上条码)格式有误.");
                    }
                    //批号
                    data.LotBatch = arr[1];
                    //料号
                    data.PartNum = arr[0].ToUpper();
                    //叠合次数号
                    data.HeapNumber = "9";
                    //材料类型
                    data.MaterialType = "Cu_pp";
                    //长度数组
                    var Lengths = new List<int>() { 6, 7, 8 };
                    //长度验证
                    if (Lengths.Any(item => item == data.PartNum.Length))
                    {
                        partNum = data.PartNum.Substring(0, data.PartNum.Length - 1);
                    }
                    else
                    {
                        partNum = data.PartNum;
                    }
                }

                //获取配置
                var configs = GetConfig();

                #region 操作设定

                #region 数据处理
                var opSetUpList = configs.Where(c => c.Type == (int)SettingType.操作设定).ToList();
                //操作设定
                var newOpSet = new List<OpSetUpResponse>();
                //批量添加
                opSetUpList.ForEach(parentItem => {

                    var arr = parentItem.PartNo.Split(";");
                    if (arr.Length > 2)
                    {
                        foreach(string childItem in arr)
                        {
                            var partNo = childItem.Replace(";", "").ToUpper();

                            if (!string.IsNullOrEmpty(partNo))
                            {
                                newOpSet.Add(new OpSetUpResponse()
                                {
                                    PartNo = partNo,
                                    LotNo = parentItem.LotNo,
                                    Cycle = parentItem.Cycle,
                                    Value = parentItem.Value
                                });
                            }
                        }
                    }
                    else
                    {
                        newOpSet.Add(new OpSetUpResponse() {
                            PartNo = parentItem.PartNo.Replace(";", "").ToUpper(),
                            LotNo = parentItem.LotNo,
                            Cycle = parentItem.Cycle,
                            Value = parentItem.Value
                        });
                    }
                });
                #endregion

                #region 数据匹配

                if (newOpSet != null && newOpSet.Any())
                {
                    //批号
                    var configBatch = newOpSet.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == data.LotBatch && c.Cycle == data.HeapNumber);
                    if(configBatch != null)
                    {
                        data.Tips = configBatch.Value;
                    }
                    else
                    {
                        //获取配置
                        var config = newOpSet.FirstOrDefault(c => c.PartNo == data.PartNum && c.Cycle == data.HeapNumber);
                        //验证
                        if (config != null)
                        {
                            data.Tips = config.Value;
                        }
                        else
                        {
                            //获取配置
                            config = newOpSet.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == data.HeapNumber);
                            if (config != null)
                            {
                                data.Tips = config.Value;
                            }
                        }
                    }
                }

                #endregion

                #endregion

                #region 程序设定

                var pressProgramList = configs.Where(c => c.Type == (int)SettingType.程序).ToList();
                if (pressProgramList != null && pressProgramList.Any())
                {
                    //批号
                    var pressProgramBatch = pressProgramList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == data.LotBatch && c.Cycle == data.HeapNumber);
                    if (pressProgramBatch != null)
                    {
                        data.Tips += $"<br><p>工程师设定压合程式:{pressProgramBatch.Value}</p>";

                        data.PressProgram = pressProgramBatch.Value;
                    }
                    else
                    {
                        //获取配置
                        var pressProgramConfig = pressProgramList.FirstOrDefault(c => c.PartNo == data.PartNum && c.Cycle == data.HeapNumber);
                        //验证
                        if (pressProgramConfig != null)
                        {
                            data.Tips += $"<br><p>工程师设定压合程式:{pressProgramConfig.Value}</p>";

                            data.PressProgram = pressProgramConfig.Value;
                        }
                        else
                        {
                            //获取配置
                            pressProgramConfig = pressProgramList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == data.HeapNumber);
                            if (pressProgramConfig != null)
                            {
                                data.Tips += $"<br><p>工程师设定压合程式:{pressProgramConfig.Value}</p>";

                                data.PressProgram = pressProgramConfig.Value;
                            }
                        }
                    }

                }

                #endregion

                #region Book结构

                var bookSetUpList = configs.Where(c => c.Type == (int)SettingType.Book结构).ToList();
                if (bookSetUpList != null && bookSetUpList.Any())
                {
                    //批号
                    var bookSetUpBatch = pressProgramList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == data.LotBatch && c.Cycle == data.HeapNumber);
                    if (bookSetUpBatch != null)
                    {
                        data.Tips += $"<br><p>工程师设定满本结构:{bookSetUpBatch.Value}</p>";

                        data.BookBuildupStructure = bookSetUpBatch.Value;
                    }
                    else
                    {
                        //获取配置
                        var bookSetUpConfig = bookSetUpList.FirstOrDefault(c => c.PartNo == data.PartNum && c.Cycle == data.HeapNumber);
                        //验证
                        if (bookSetUpConfig != null)
                        {
                            data.Tips += $"<br><p>工程师设定满本结构:{bookSetUpConfig.Value}</p>";

                            data.BookBuildupStructure = bookSetUpConfig.Value;
                        }
                        else
                        {
                            //获取配置
                            bookSetUpConfig = bookSetUpList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == data.HeapNumber);
                            if (bookSetUpConfig != null)
                            {
                                data.Tips += $"<br><p>工程师设定满本结构:{bookSetUpConfig.Value}</p>";

                                data.BookBuildupStructure = bookSetUpConfig.Value;
                            }
                        }
                    }

                }
                #endregion

                #region 板数设定
                var heapSetUpList = configs.Where(c => c.Type == (int)SettingType.叠板片数设定).ToList();
                if (heapSetUpList != null && heapSetUpList.Any())
                {
                    //批号
                    var heapSetUpBatch = heapSetUpList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == data.LotBatch && c.Cycle == data.HeapNumber);
                    if (heapSetUpBatch != null)
                    {
                        data.Tips += $"<br><p>板数不能超{heapSetUpBatch.Value}片</p>";
                    }
                    else
                    {
                        //获取配置
                        var heapSetUp = heapSetUpList.FirstOrDefault(c => c.PartNo == data.PartNum && c.Cycle == data.HeapNumber);
                        //验证
                        if (heapSetUp != null)
                        {
                            data.Tips += $"<br><p>板数不能超{heapSetUp.Value}片</p>";
                        }
                        else
                        {
                            //获取配置
                            heapSetUp = heapSetUpList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == data.HeapNumber);
                            if (heapSetUp != null)
                            {
                                data.Tips += $"<br><p>板数不能超{heapSetUp.Value}片</p>";
                            }
                        }
                    }
                }
                #endregion

                #region 机台设定
                var machineSetUpList = configs.Where(c => c.Type == (int)SettingType.机台设定 && c.PartNo == data.PartNum && c.Cycle == data.HeapNumber).ToList();
                if (machineSetUpList != null && machineSetUpList.Any())
                {
                    var sb = new StringBuilder();

                    machineSetUpList.ForEach(item => {
                        sb.Append(item.Value + "、");
                    });

                    data.Tips += $"<br><p>料号{data.PartNum}、叠合次数号:{data.HeapNumber},仅限于{sb.ToString().TrimEnd('、')}机台</p>";
                }
                else
                {
                    machineSetUpList = configs.Where(c => c.Type == (int)SettingType.机台设定 && c.PartNo.Contains(partNum) && c.Cycle == data.HeapNumber).ToList();
                    if (machineSetUpList != null && machineSetUpList.Any())
                    {
                        var sb = new StringBuilder();

                        machineSetUpList.ForEach(item => {
                            sb.Append(item.Value + "、");
                        });

                        if (!machineSetUpList.Any(c => c.Value == reqeust.EquipmentCode))
                        {
                            data.Tips += $"<br><p>料号{partNum}、叠合次数号:{data.HeapNumber},仅限于{sb.ToString().TrimEnd('、')}机台</p>";
                        }
                    }
                }
                #endregion

                #region PP 半固化片数量
                try
                {
                    //查询查询
                    //开始时间
                    var startTime = DateTime.Now.AddDays(-180).ToString("yyyy-MM-dd HH:mm:ss");
                    //结束时间
                    var endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                    var iqsQuerySql =  string.Format("select PartNum,PpNumber from IQS where PartNum='{0}' And HeapNumber='{1}' And CreatedDate BETWEEN '{2}' AND '{3}'  ORDER BY CreatedDate DESC LIMIT 0,1", data.PartNum, data.HeapNumber, startTime, endTime);
                    //执行查询
                    var iqs = _db.DbConnection.Query<IQS>(iqsQuerySql).FirstOrDefault();
                    if (iqs != null)
                    {
                        data.PpNumber = iqs.PpNumber.ToString();
                    }
                    else
                    {
                        iqsQuerySql = string.Format("select PartNum,PpNumber from IQS where PartNum='{0}' And HeapNumber='{1}' And CreatedDate BETWEEN '{2}' AND '{3}'  ORDER BY CreatedDate DESC LIMIT 0,1", partNum, data.HeapNumber, startTime, endTime);
                        //执行查询
                        iqs = _db.DbConnection.Query<IQS>(iqsQuerySql).FirstOrDefault();
                        if (iqs != null)
                        {
                            data.PpNumber = iqs.PpNumber.ToString();
                        }
                    }
                }
                catch (Exception ex)
                {
                    response.Message = ex.Message;
                }
                #endregion

                #region 信息验证
                var infos = GetInfos(new InfoQuery() {
                    EquipmentCode = reqeust.EquipmentCode,
                    StaffNum = reqeust.StaffNum,
                    ShiftNum = reqeust.ShiftNum
                });

                if (infos != null && infos.Any())
                    data.Count = infos.Count;
                else
                    data.Count = 0;
                #endregion

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region programbarCode 物料/程式信息(下条码)
        /// <summary>
        /// 物料/程式信息(下条码)
        /// </summary>
        [HttpPost]
        public IActionResult ProgrambarCode(ProgrambarCodeReqeust reqeust)
        {
            var response = new JResult<ProgrambarCodeResponse>()
            {
                Success = false
            };

            try
            {
                var data = new ProgrambarCodeResponse();
                //材料类型
                data.MaterialType = reqeust.MaterialType;
                //验证是否为空.
                if (string.IsNullOrEmpty(reqeust.ProgrambarCode))
                {
                    throw new Exception("扫码内容不能为空.");
                }
                //下条码
                data.LowerBarCode = reqeust.ProgrambarCode;
                //转换为数组
                var arr = reqeust.ProgrambarCode.Split("|");

                if (arr.Length < 4)
                {
                    throw new Exception("扫码内容格式有误.");
                }

                //铜箔
                data.CuFoilNum = arr[0];
                //PP1
                data.PPRCFPartNum1 = arr[1];
                //PP2
                data.PPRCFPartNum2 = arr[2];
                //压合程式
                data.PressProgram = arr[3].Replace("_", "").Replace("-", "").Replace(" ", "").ToUpper();
                //满本结构
                if (arr.Length > 4)
                {
                    if (string.IsNullOrEmpty(reqeust.BookBuildupStructure))
                        data.BookBuildupStructure = arr[4].ToUpper();
                    else
                        data.BookBuildupStructure = reqeust.BookBuildupStructure;

                    data.Thickness = float.Parse(arr[5]);
                    //获取配置
                    var configs = GetConfig();
                    //标准片数
                    uint heapNumber = 30;
                    //叠板片数
                    var heapSetUpList = configs.Where(c => c.Type == (int)SettingType.叠板片数设定).ToList();
                    if (heapSetUpList != null && heapSetUpList.Any())
                    {
                        //批号
                        var heapSetUpBatch = heapSetUpList.FirstOrDefault(c => c.PartNo == reqeust.PartNum && c.LotNo == reqeust.LotBatch && c.Cycle == reqeust.HeapNumber);
                        if (heapSetUpBatch != null)
                        {
                            heapNumber = uint.Parse(heapSetUpBatch.Value);
                        }
                        else
                        {
                            //获取配置
                            var heapSetUp = heapSetUpList.FirstOrDefault(c => c.PartNo == reqeust.PartNum && c.Cycle == reqeust.HeapNumber);
                            //验证
                            if (heapSetUp != null)
                            {
                                heapNumber = uint.Parse(heapSetUp.Value);
                            }
                            else
                            {
                                //获取配置
                                //材料
                                var partNum = "";
                                //长度数组
                                var Lengths = new List<int>() { 6, 7, 8 };
                                //长度验证
                                if (Lengths.Any(item => item == reqeust.PartNum.Length))
                                {
                                    partNum = reqeust.PartNum.Substring(0, reqeust.PartNum.Length - 1);
                                }
                                else
                                {
                                    partNum = reqeust.PartNum;
                                }

                                heapSetUp = heapSetUpList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == reqeust.HeapNumber);
                                if (heapSetUp != null)
                                {
                                    heapNumber = uint.Parse(heapSetUp.Value);
                                }
                            }
                        }
                    }

                    var calcSteelPlateNew = new CalcSteelPlateNew();
                    //计算heapNumber
                    calcSteelPlateNew.CalcBook(data.Thickness, reqeust.TotalPanelQuan, reqeust.TotalSecionQuan, data.BookBuildupStructure, heapNumber);
                    try
                    {
                        data.BookNum = (int)(calcSteelPlateNew.BookFullNoCross.BookNums + calcSteelPlateNew.BookNoFullNoCross.BookNums + calcSteelPlateNew.BookFullOnlyCross.BookNums + calcSteelPlateNew.BookNoFullMixCross.BookNums);
                    }
                    catch (Exception exx)
                    {
                        MemoryCacheUtil.Set("bookNum", 0, 120);
                    }

                    data.PlateResponse = new PlateResponse() {
                        //无切片孔
                        NoBookNums1_1 = calcSteelPlateNew.BookFullNoCross.BookNums.ToString(),
                        NoCommPlate1_1 = calcSteelPlateNew.BookFullNoCross.CommPlate.ToString(),
                        NoUpSteelPlateNums1_1 = calcSteelPlateNew.BookFullNoCross.UpSteelPlateNums.ToString(),
                        NoDownSteelPlateNums1_1 = calcSteelPlateNew.BookFullNoCross.DownSteelPlateNums.ToString(),

                        NoBookNums1_2 = calcSteelPlateNew.BookNoFullNoCross.BookNums.ToString(),
                        NoCommPlate1_2 = calcSteelPlateNew.BookNoFullNoCross.CommPlate.ToString(),
                        NoUpSteelPlateNums1_2 = calcSteelPlateNew.BookNoFullNoCross.UpSteelPlateNums.ToString(),
                        NoDownSteelPlateNums1_2 = calcSteelPlateNew.BookNoFullNoCross.DownSteelPlateNums.ToString(),
                        //有切片孔
                        BookNums2_1 = calcSteelPlateNew.BookFullOnlyCross.BookNums.ToString(),
                        CommPlate2_1 = (calcSteelPlateNew.BookFullOnlyCross.CommPlate + calcSteelPlateNew.BookFullOnlyCross.CrossPlate).ToString(),
                        CrossPlate2_1 = calcSteelPlateNew.BookFullOnlyCross.CrossPlate.ToString(),
                        UpSteelPlateNums2_1 = calcSteelPlateNew.BookFullOnlyCross.UpSteelPlateNums.ToString(),
                        DownSteelPlateNums2_1 = calcSteelPlateNew.BookFullOnlyCross.DownSteelPlateNums.ToString(),

                        BookNums2_2 = calcSteelPlateNew.BookNoFullMixCross.BookNums.ToString(),
                        CommPlate2_2 = (calcSteelPlateNew.BookNoFullMixCross.CommPlate + calcSteelPlateNew.BookNoFullMixCross.CrossPlate).ToString(),
                        CrossPlate2_2 = calcSteelPlateNew.BookNoFullMixCross.CrossPlate.ToString(),
                        UpSteelPlateNums2_2 = calcSteelPlateNew.BookNoFullMixCross.UpSteelPlateNums.ToString(),
                        DownSteelPlateNums2_2 = calcSteelPlateNew.BookNoFullMixCross.DownSteelPlateNums.ToString(),
                    };
                }

                data.TravellerDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //获取配置
                //var dictionarys = GetDictionary();
                //获取压合程式所有数据
                //var dictionaryList = dictionarys.Where(c => c.Type == (int)DictionaryFiled.压合程式);
                //if (dictionaryList != null && dictionaryList.Any())
                //{
                //    var dictionary = dictionaryList.FirstOrDefault(c => c.Name.Replace("_", "").Replace("-", "").Replace(" ", "").ToUpper() == data.PressProgram);
                //    if (dictionary != null)
                //    {
                //        data.PressProgram = dictionary.Name;
                //    }
                //    else
                //    {
                //        data.PressProgram = "";
                //    }
                //}

                #region 流程验证
                if (reqeust.MaterialType == "Cu_pp")
                {
                    //416278|414930|000000|EMC21|LA12|0.4010
                    //416278|414930|414931|EMC21|LA12|0.4010
                    #region Cu_pp
                    //PP 半固化片种类数
                    int ppTypeNumber = 0;
                    //铜箔编号
                    var cuFoilNumReg = new Regex(@"^000000");
                    if (cuFoilNumReg.IsMatch(data.CuFoilNum))
                    {
                        throw new Exception("铜箔编号有误.");
                    }

                    cuFoilNumReg = new Regex(@"^[0-9]{6}$");
                    if (!cuFoilNumReg.IsMatch(data.CuFoilNum))
                    {
                        throw new Exception("铜箔编号由6位数字组成.");
                    }

                    //PP1
                    var ppRCFPartNum1Reg = new Regex(@"^000000");
                    if (ppRCFPartNum1Reg.IsMatch(data.PPRCFPartNum1))
                    {
                        throw new Exception("PP料号1格式有误.");
                    }

                    ppRCFPartNum1Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppRCFPartNum1Reg.IsMatch(data.PPRCFPartNum1))
                    {
                        throw new Exception("PP料号1由6位数字组成.");
                    }
                    else
                        ppTypeNumber++;

                    //PP2
                    var ppRCFPartNum2Reg = new Regex(@"^000000");
                    if (!ppRCFPartNum2Reg.IsMatch(data.PPRCFPartNum2))
                    {
                        ppTypeNumber++;
                    }

                    ppRCFPartNum2Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppRCFPartNum2Reg.IsMatch(data.PPRCFPartNum2))
                    {
                        throw new Exception("PP料号2由6位数字组成.");
                    }

                    data.ProgressStatus = true;
                    data.PPTypeNumber = ppTypeNumber;
                    #endregion
                }
                else if(reqeust.MaterialType == "RCF")
                {
                    //000000|413251|000000|Long_dIMPLE18|LA3|0.2942
                    #region RCF
                    //PP 半固化片种类数
                    int ppTypeNumber = 0;
                    //铜箔编号
                    var cuFoilNumReg = new Regex(@"^000000");
                    if (!cuFoilNumReg.IsMatch(data.CuFoilNum))
                    {
                        throw new Exception("铜箔编号有误.");
                    }

                    cuFoilNumReg = new Regex(@"^[0-9]{6}$");
                    if (!cuFoilNumReg.IsMatch(data.CuFoilNum))
                    {
                        throw new Exception("铜箔编号由6位数字组成.");
                    }

                    //PP1
                    var ppRCFPartNum1Reg = new Regex(@"^000000");
                    if (ppRCFPartNum1Reg.IsMatch(data.PPRCFPartNum1))
                    {
                        throw new Exception("PP料号1格式有误.");
                    }

                    ppRCFPartNum1Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppRCFPartNum1Reg.IsMatch(data.PPRCFPartNum1))
                    {
                        throw new Exception("PP料号1由6位数字组成.");
                    }
                    else
                        ppTypeNumber++;

                    //PP2
                    var ppRCFPartNum2Reg = new Regex(@"^000000");
                    if (!ppRCFPartNum2Reg.IsMatch(data.PPRCFPartNum2))
                    {
                        ppRCFPartNum2Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppRCFPartNum2Reg.IsMatch(data.PPRCFPartNum2))
                        {
                            throw new Exception("PP料号2由6位数字组成.");
                        }

                        ppTypeNumber++;
                    }

                    data.ProgressStatus = true;
                    data.PPTypeNumber = ppTypeNumber;
                    #endregion
                }
                else if (reqeust.MaterialType == "OnlyPP")
                {
                    //000000|413251|000000|Long_dIMPLE18|LA3|0.2942
                    #region OnlyPP
                    //PP 半固化片种类数
                    int ppTypeNumber = 0;
                    //铜箔编号
                    var cuFoilNumReg = new Regex(@"^000000");
                    if (!cuFoilNumReg.IsMatch(data.CuFoilNum))
                    {
                        throw new Exception("铜箔编号有误.");
                    }

                    cuFoilNumReg = new Regex(@"^[0-9]{6}$");
                    if (!cuFoilNumReg.IsMatch(data.CuFoilNum))
                    {
                        throw new Exception("铜箔编号由6位数字组成.");
                    }

                    //PP1
                    var ppRCFPartNum1Reg = new Regex(@"^000000");
                    if (ppRCFPartNum1Reg.IsMatch(data.PPRCFPartNum1))
                    {
                        throw new Exception("PP料号1格式有误.");
                    }

                    ppRCFPartNum1Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppRCFPartNum1Reg.IsMatch(data.PPRCFPartNum1))
                    {
                        throw new Exception("PP料号1由6位数字组成.");
                    }
                    else
                        ppTypeNumber++;

                    //PP2
                    var ppRCFPartNum2Reg = new Regex(@"^000000");
                    if (!ppRCFPartNum2Reg.IsMatch(data.PPRCFPartNum2))
                    {
                        ppRCFPartNum2Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppRCFPartNum2Reg.IsMatch(data.PPRCFPartNum2))
                        {
                            throw new Exception("PP料号2由6位数字组成.");
                        }

                        ppTypeNumber++;
                    }

                    data.ProgressStatus = true;
                    data.PPTypeNumber = ppTypeNumber;
                    #endregion
                }
                else if (reqeust.MaterialType == "GE02/CUSHI")
                {
                    //000000|000000|000000|Long_dIMPLE18|LA3|0.2942
                    #region GE02/CUSHI
                    //PP 半固化片种类数
                    int ppTypeNumber = 0;
                    //铜箔编号
                    var cuFoilNumReg = new Regex(@"^000000");
                    if (!cuFoilNumReg.IsMatch(data.CuFoilNum))
                    {
                        throw new Exception("铜箔编号有误.");
                    }

                    cuFoilNumReg = new Regex(@"^[0-9]{6}$");
                    if (!cuFoilNumReg.IsMatch(data.CuFoilNum))
                    {
                        throw new Exception("铜箔编号由6位数字组成.");
                    }

                    //PP1
                    var ppRCFPartNum1Reg = new Regex(@"^000000");
                    if (!ppRCFPartNum1Reg.IsMatch(data.PPRCFPartNum1))
                    {
                        throw new Exception("PP料号1格式有误.");
                    }

                    ppRCFPartNum1Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppRCFPartNum1Reg.IsMatch(data.PPRCFPartNum1))
                    {
                        throw new Exception("PP料号1由6位数字组成.");
                    }

                    //PP2
                    var ppRCFPartNum2Reg = new Regex(@"^000000");
                    if (!ppRCFPartNum2Reg.IsMatch(data.PPRCFPartNum2))
                    {
                        throw new Exception("PP料号2格式有误.");
                    }

                    ppRCFPartNum2Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppRCFPartNum2Reg.IsMatch(data.PPRCFPartNum2))
                    {
                        throw new Exception("PP料号2由6位数字组成.");
                    }

                    data.ProgressStatus = true;
                    data.PPTypeNumber = ppTypeNumber;
                    #endregion
                }
                else if (reqeust.MaterialType == "GE02/CUSHI")
                {
                    #region
                    #endregion
                }
                else
                {
                    throw new Exception("材料类型有误.");
                }
                #endregion

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Cu Foil Num 铜箔编号
        /// <summary>
        /// Cu Foil Num 铜箔编号
        /// </summary>
        [HttpPost]
        public IActionResult CuFoilNum(MaterialTypeRequest request)
        {
            var response = new JResult<CuFoilNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new CuFoilNumResponse();

                if (string.IsNullOrEmpty(request.PressProgramCuFoilNum))
                {
                    throw new Exception("物料/程式信息铜箔编号不能为空.");
                }

                if (string.IsNullOrEmpty(request.CuFoilNum))
                {
                    throw new Exception("扫码内容不能为空.");
                }

                if (string.IsNullOrEmpty(request.MaterialType))
                {
                    throw new Exception("材料类型不能为空.");
                }

                var arr = request.CuFoilNum.Split("*");

                if (arr.Length < 2)
                {
                    throw new Exception("扫码内容格式有误.");
                }

                if (request.MaterialType == "Cu_pp")
                {
                    //416278|414930|000000|EMC21|LA12|0.4010
                    //416278|414930|414931|EMC21|LA12|0.4010
                    #region Cu_pp
                    //铜箔编号
                    data.CuFoilNum = arr[0];
                    //铜箔批号
                    var cufoilBatch = arr[1];

                    if (arr.Length >= 3)
                    {
                        cufoilBatch += $"*{arr[1]}";
                    }

                    data.CuFoilBatch = cufoilBatch;

                    if (data.CuFoilNum != request.PressProgramCuFoilNum)
                    {
                        throw new Exception("与物料/程式信息铜箔编号不复.");
                    }
                    #endregion
                }
                else if (request.MaterialType == "RCF")
                {
                    //000000|413251|000000|Long_dIMPLE18|LA3|0.2942
                    #region RCF
                    //铜箔编号
                    data.CuFoilNum = arr[0];
                    //铜箔批号
                    var cufoilBatch = arr[1];

                    if (arr.Length >= 3)
                    {
                        cufoilBatch += $"*{arr[1]}";
                    }

                    data.CuFoilBatch = cufoilBatch;
                    #endregion
                }
                else if (request.MaterialType == "OnlyPP")
                {
                    //000000|413251|000000|Long_dIMPLE18|LA3|0.2942
                    #region OnlyPP
                    //铜箔编号
                    data.CuFoilNum = arr[0];
                    //铜箔批号
                    var cufoilBatch = arr[1];

                    if (arr.Length >= 3)
                    {
                        cufoilBatch += $"*{arr[1]}";
                    }

                    data.CuFoilBatch = cufoilBatch;
                    #endregion
                }
                else if (request.MaterialType == "GE02/CUSHI")
                {
                    //000000|000000|000000|Long_dIMPLE18|LA3|0.2942
                    #region GE02/CUSHI
                    //铜箔编号
                    data.CuFoilNum = arr[0];
                    //铜箔批号
                    var cufoilBatch = arr[1];

                    if (arr.Length >= 3)
                    {
                        cufoilBatch += $"*{arr[1]}";
                    }

                    data.CuFoilBatch = cufoilBatch;
                    #endregion
                }
                else
                {
                    throw new Exception("材料类型有误.");
                }


                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Cu Foil Expire 铜箔有效期
        /// <summary>
        /// Cu Foil Expire 铜箔有效期
        /// </summary>
        [HttpPost]
        public IActionResult CuFoilExpire(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 必须大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Cu Foil Expire 铜箔有效期不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"Cu Foil Expire 铜箔有效期[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date < now)
                {
                    throw new Exception(@$"Cu Foil Expire 铜箔有效期[{content}]必须大于当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Package Num包号1_1
        /// <summary>
        /// Package Num包号1
        /// </summary>
        [HttpPost]
        public IActionResult PackageNum1_1(string content)
        {
            var response = new JResult<PackageNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new PackageNumResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Package Num包号1_1不能为空.");
                }

                //21-1018-0936222022/01/11;240
                //21-1018-093622;2022/01/11;240
                var arr = content.Split(";");

                if (arr.Length >= 2)
                {
                    data.PackageNum = arr[0];
                    data.PackageExpire = arr[1];
                    data.MaterialDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    try
                    {
                        //包号时间
                        var packageNumTime = DateTime.ParseExact(data.PackageNum.Replace("-", ""), "yyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                        //时间差
                        TimeSpan ts  = DateTime.Now - packageNumTime;
                        if (ts.TotalHours < 8)
                        {
                            data.Expire = "冷却时间必须大于8小时";
                        }
                    }
                    catch(Exception ex)
                    {

                    }
                    //当前时间-包号=    大于8小时

                    response.Success = true;
                    response.Data = data;
                }
                else
                {
                    throw new Exception("Package Num包号1_1格式有误.");
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 料号1_1
        /// <summary>
        /// PP/PCF 料号1
        /// </summary>
        [HttpPost]
        public JsonResult PpPcfPartNum1_1(string content)
        {
            var response = new JResult<PpPcfPartNum1_1Response>()
            {
                Success = false
            };

            try
            {
                var data = new PpPcfPartNum1_1Response();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("料号1内容不能为空.");
                }

                var exist = content.Contains(";");
                if(exist)
                {
                    //料号   批号
                    //414910;21A042M01A3;240;
                    var arr = content.Split(";");

                    if (arr.Length >= 2)
                    {
                        response.Success = true;
                        response.Data = new PpPcfPartNum1_1Response()
                        {
                            PPPcfPartNum1 = arr[0],
                            PPPcfBatchNum1 = arr[1]
                        };
                    }
                    else
                    {
                        throw new Exception("料号1_1内容格式有误.");
                    }
                }
                else
                {
                    //	              0241料号           0010批号
                    //|00404500948712|0241414930|0037240|001021A042M01A3|0036036|0011211004|0412470433|0048|
                    //
                    var arr = content.Split("|");

                    var partNum = arr.FirstOrDefault(c => c.Contains("0241"));
                    if (partNum != null)
                    {
                        data.PPPcfPartNum1 = partNum.Replace("0241", "");
                    }

                    var batchNum = arr.FirstOrDefault(c => c.Contains("0010"));
                    if (batchNum != null)
                    {
                        data.PPPcfBatchNum1 = batchNum.Replace("0010", "");
                    }

                    response.Success = true;
                    response.Data = data;
                }

                #region 备份
                //if (status)
                //{
                //    //料号   批号
                //    //414910;21A042M01A3;240;
                //    var arr = content.Split(";");

                //    if (arr.Length >= 2)
                //    {
                //        data.PPPcfPartNum1 = arr[0];
                //        data.PPPcfBatchNum1 = arr[1];
                //    }
                //    else
                //    {
                //        throw new Exception("料号1_1内容格式有误.");
                //    }
                //}
                //else
                //{
                //    //	              0241料号           0010批号
                //    //|00404500948712|0241414910|0037240|001021A042M01A3|0036036|0011211004|0412470433|0048|
                //    //
                //    var arr = content.Split("|");

                //    if (arr.Length != 11)
                //    {
                //        var partNum = arr.FirstOrDefault(c => c.Contains("0241"));
                //        if (partNum != null)
                //        {
                //            data.PPPcfPartNum1 = partNum.Replace("0241", "");
                //        }

                //        var batchNum = arr.FirstOrDefault(c => c.Contains("0010"));
                //        if (batchNum != null)
                //        {
                //            data.PPPcfBatchNum1 = batchNum.Replace("0010", "");
                //        }
                //    }
                //    else
                //    {
                //        throw new Exception("料号1内容格式有误.");
                //    }
                //}

                //var data = new List<string>();


                //if (data[0] != LOTPPRCFPartNum1)
                //{
                //    throw new Exception(@$"与物料/程式信息(下条码)******|{LOTPPRCFPartNum1}|******|*****|****|******不匹配.");
                //}
                #endregion
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 有效期1_1
        /// <summary>
        /// PP/PCF 有效期1
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfExpire1_1(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 不能大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("PP/PCF 有效期1_1不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"PP/PCF 有效期1_1[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date < now)
                {
                    throw new Exception("PP/PCF 有效期1_1必须大于当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Package Num包号1_2
        /// <summary>
        /// Package Num包号1
        /// </summary>
        [HttpPost]
        public IActionResult PackageNum1_2(string content)
        {
            var response = new JResult<PackageNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new PackageNumResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Package Num包号1_2不能为空.");
                }

                //21-1018-0936222022/01/11;240
                //21-1018-093622;2022/01/11;240
                var arr = content.Split(";");

                if (arr.Length >= 2)
                {
                    data.PackageNum = arr[0];
                    data.PackageExpire = arr[1];
                    try
                    {
                        //包号时间
                        var packageNumTime = DateTime.ParseExact(data.PackageNum.Replace("-", ""), "yyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                        //时间差
                        TimeSpan ts = DateTime.Now - packageNumTime;
                        if (ts.TotalHours < 8)
                        {
                            data.Expire = "冷却时间必须大于8小时";
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                    response.Data = data;
                    response.Success = true;
                }
                else
                {
                    throw new Exception("Package Num包号1_2格式有误.");
                }

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 料号1_2
        /// <summary>
        /// PP/PCF 料号1
        /// </summary>
        [HttpPost]
        public JsonResult PpPcfPartNum1_2( string content)
        {
            var response = new JResult<PpPcfPartNum1_1Response>()
            {
                Success = false
            };

            try
            {
                var data = new PpPcfPartNum1_1Response();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("料号1_2内容不能为空.");
                }

                var exist = content.Contains(";");
                if (exist)
                {
                    //料号   批号
                    //414910;21A042M01A3;240;
                    var arr = content.Split(";");

                    if (arr.Length >= 2)
                    {
                        response.Success = true;
                        response.Data = new PpPcfPartNum1_1Response()
                        {
                            PPPcfPartNum1 = arr[0],
                            PPPcfBatchNum1 = arr[1]
                        };
                    }
                    else
                    {
                        throw new Exception("料号1_2内容格式有误.");
                    }
                }
                else
                {
                    //	              0241料号           0010批号
                    //|00404500948712|0241414930|0037240|001021A042M01A3|0036036|0011211004|0412470433|0048|
                    //
                    var arr = content.Split("|");

                    var partNum = arr.FirstOrDefault(c => c.Contains("0241"));
                    if (partNum != null)
                    {
                        data.PPPcfPartNum1 = partNum.Replace("0241", "");
                    }

                    var batchNum = arr.FirstOrDefault(c => c.Contains("0010"));
                    if (batchNum != null)
                    {
                        data.PPPcfBatchNum1 = batchNum.Replace("0010", "");
                    }

                    response.Success = true;
                    response.Data = data;
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 有效期1_2
        /// <summary>
        /// PP/PCF 有效期1
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfExpire1_2(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 不能大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("PP/PCF 有效期1_2不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"PP/PCF 有效期1_2[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date < now)
                {
                    throw new Exception("PP/PCF 有效期1_2必须大于当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Package Num包号2_1
        /// <summary>
        /// Package Num包号2
        /// </summary>
        [HttpPost]
        public IActionResult PackageNum2_1(string content)
        {
            var response = new JResult<PackageNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new PackageNumResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Package Num包号2_1不能为空.");
                }

                //21-1018-0936222022/01/11;240
                //21-1018-093622;2022/01/11;240
                var arr = content.Split(";");

                if (arr.Length >= 2)
                {
                    data.PackageNum = arr[0];
                    data.PackageExpire = arr[1];
                    try
                    {
                        //包号时间
                        var packageNumTime = DateTime.ParseExact(data.PackageNum.Replace("-", ""), "yyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                        //时间差
                        TimeSpan ts = DateTime.Now - packageNumTime;
                        if (ts.TotalHours < 8)
                        {
                            data.Expire = "冷却时间必须大于8小时";
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                    response.Success = true;
                    response.Data = data;
                }
                else
                {
                    throw new Exception("Package Num包号2_1格式有误.");
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 料号2_1
        /// <summary>
        /// PP/PCF 料号1
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfPartNum2_1(string content)
        {
            var response = new JResult<PpPcfPartNum1_1Response>()
            {
                Success = false
            };

            try
            {
                var data = new PpPcfPartNum1_1Response();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("料号2_1内容不能为空.");
                }

                var exist = content.Contains(";");
                if (exist)
                {
                    //料号   批号
                    //414910;21A042M01A3;240;
                    var arr = content.Split(";");

                    if (arr.Length >= 2)
                    {
                        response.Success = true;
                        response.Data = new PpPcfPartNum1_1Response()
                        {
                            PPPcfPartNum1 = arr[0],
                            PPPcfBatchNum1 = arr[1]
                        };
                    }
                    else
                    {
                        throw new Exception("料号2_1内容格式有误.");
                    }
                }
                else
                {
                    //	              0241料号           0010批号
                    //|00404500948712|0241414930|0037240|001021A042M01A3|0036036|0011211004|0412470433|0048|
                    //
                    var arr = content.Split("|");

                    var partNum = arr.FirstOrDefault(c => c.Contains("0241"));
                    if (partNum != null)
                    {
                        data.PPPcfPartNum1 = partNum.Replace("0241", "");
                    }

                    var batchNum = arr.FirstOrDefault(c => c.Contains("0010"));
                    if (batchNum != null)
                    {
                        data.PPPcfBatchNum1 = batchNum.Replace("0010", "");
                    }

                    response.Success = true;
                    response.Data = data;
                }

                #region 备份
                //var status = content.Contains(";");

                //if(status){
                //    //料号   批号
                //    //414910;21A042M01A3;240;
                //    var arr = content.Split(";");
                //    if (arr.Length >= 2)
                //    {
                //        data.PPPcfPartNum1 = arr[0];
                //        data.PPPcfBatchNum1 = arr[1];
                //    }
                //    else
                //    {
                //        throw new Exception("料号2_1内容格式有误.");
                //    }

                //    if (data.PPPcfPartNum1 != LOTPPRCFPartNum2)
                //    {
                //        throw new Exception(@$"与物料/程式信息(下条码)******|******|{LOTPPRCFPartNum2}|*****|****|******不匹配.");
                //    }

                //    response.Success = true;
                //    response.Data = data;
                //}
                //else
                //{

                //}
                #endregion
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 有效期2_1
        /// <summary>
        /// PP/PCF 有效期2
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfExpire2_1(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 不能大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("PP/PCF 有效期2_1不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"PP/PCF 有效期2_1[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date < now)
                {
                    throw new Exception("PP/PCF 有效期2_1必须当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Package Num包号2_2
        /// <summary>
        /// Package Num包号2
        /// </summary>
        [HttpPost]
        public IActionResult PackageNum2_2(string content)
        {
            var response = new JResult<PackageNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new PackageNumResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Package Num包号2_2不能为空.");
                }

                //21-1018-0936222022/01/11;240
                //21-1018-093622;2022/01/11;240
                var arr = content.Split(";");

                if (arr.Length >= 2)
                {
                    data.PackageNum = arr[0];
                    data.PackageExpire = arr[1];
                    try
                    {
                        //包号时间
                        var packageNumTime = DateTime.ParseExact(data.PackageNum.Replace("-", ""), "yyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                        //时间差
                        TimeSpan ts = DateTime.Now - packageNumTime;
                        if (ts.TotalHours < 8)
                        {
                            data.Expire = "冷却时间必须大于8小时";
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                    response.Data = data;
                    response.Success = true;
                }
                else
                {
                    throw new Exception("Package Num包号2_2格式有误.");
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 料号2_2
        /// <summary>
        /// PP/PCF 料号1
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfPartNum2_2(string content)
        {
            var response = new JResult<PpPcfPartNum1_1Response>()
            {
                Success = false
            };

            try
            {
                var data = new PpPcfPartNum1_1Response();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("料号2_1内容不能为空.");
                }

                var exist = content.Contains(";");
                if (exist)
                {
                    //料号   批号
                    //414910;21A042M01A3;240;
                    var arr = content.Split(";");

                    if (arr.Length >= 2)
                    {
                        response.Success = true;
                        response.Data = new PpPcfPartNum1_1Response()
                        {
                            PPPcfPartNum1 = arr[0],
                            PPPcfBatchNum1 = arr[1]
                        };
                    }
                    else
                    {
                        throw new Exception("料号2_1内容格式有误.");
                    }
                }
                else
                {
                    //	              0241料号           0010批号
                    //|00404500948712|0241414930|0037240|001021A042M01A3|0036036|0011211004|0412470433|0048|
                    //
                    var arr = content.Split("|");

                    var partNum = arr.FirstOrDefault(c => c.Contains("0241"));
                    if (partNum != null)
                    {
                        data.PPPcfPartNum1 = partNum.Replace("0241", "");
                    }

                    var batchNum = arr.FirstOrDefault(c => c.Contains("0010"));
                    if (batchNum != null)
                    {
                        data.PPPcfBatchNum1 = batchNum.Replace("0010", "");
                    }

                    response.Success = true;
                    response.Data = data;
                }

            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 有效期2_2
        /// <summary>
        /// PP/PCF 有效期2
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfExpire2_2(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 不能大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("PP/PCF 有效期2_2不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"PP/PCF 有效期2_2[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date > now)
                {
                    throw new Exception("PP/PCF 有效期2_2不能大于当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Alpha Board Stay Time棕化停留时间
        /// <summary>
        /// Alpha Board Stay Time棕化停留时间
        /// </summary>
        [HttpPost]
        public IActionResult AlphaBoardStayTime(string content)
        {
            var response = new JResult<string>()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("棕化停留时间不能为空.");
                }

                var nameReg = new Regex(@"^[+]{0,1}(\d+)$");
                if (!nameReg.IsMatch(content))
                {
                    throw new Exception("棕化停留时间只能输入正整数");
                }

                response.Success = true;
                response.Data = content;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Abnormal Steel Plate Quantity异常钢板数量
        /// <summary>
        /// Abnormal Steel Plate Quantity异常钢板数量
        /// </summary>
        [HttpPost]
        public IActionResult AbnormalSteelPlateQuantity(string content)
        {
            var response = new JResult<string>()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("异常钢板数量不能为空.");
                }

                var nameReg = new Regex(@"^[+]{0,1}(\d+)$");
                if (!nameReg.IsMatch(content))
                {
                    throw new Exception("异常钢板数量只能输入正整数");
                }

                response.Success = true;
                response.Data = content;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #endregion

        #region Book
        /// <summary>
        /// Book
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Book()
        {
            var response = new JResult<Book>()
            {
                Success = false
            };

            try
            {
                //查询查询
                var bookQuerySql = "select * from book";
                //执行查询
                var book = _db.DbConnection.Query<Book>(bookQuerySql).FirstOrDefault();
                if(book != null)
                {
                    response.Data = book;
                    response.Success = true;
                }
            }
            catch(Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region 新增
        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <param name="request">保存参数</param>
        /// <returns></returns>
        public IActionResult Save(SaveIQSRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                #region 表单验证

                #region 头部

                #region MachineCode 机台编码
                if (string.IsNullOrEmpty(request.Account))
                {
                    throw new Exception("机台编码不能为空.");
                }

                //查询查询
                var userQuerySql = "select * from user where account=@account";
                //执行查询
                var user = _db.DbConnection.Query<User>(userQuerySql, new { account = request.Account }).FirstOrDefault();
                if (user == null)
                {
                    throw new Exception("机台编码还未设置.");
                }
                #endregion

                #region Staff Num 员工号
                //TODO(7位)
                if (string.IsNullOrEmpty(request.StaffNum))
                {
                    throw new Exception("员工号不能为空.");
                }

                var staffNumReg = new Regex(@"^28(\d+)$");
                if (!staffNumReg.IsMatch(request.StaffNum))
                {
                    throw new Exception("员工号必须以28开头且7位数字组成.");
                }

                staffNumReg = new Regex(@"^[0-9]{7}$");
                if (!staffNumReg.IsMatch(request.StaffNum))
                {
                    throw new Exception("员工号必须以28开头且7位数字组成.");
                }
                #endregion

                #region Shift Num 班次
                if (request.ShiftNum <= 0)
                {
                    throw new Exception("班次不能为空.");
                }
                #endregion

                #region 底板编码
                //底板编码
                var plantNum = 0;
                //转换
                int.TryParse(new ConfigurationBuilder().AddJsonFile("appsettings.json").Build()["Config:PlantNum"], out plantNum);
                //判断是否为空
                if (plantNum == user.PlantNum)
                {
                    //获取底板编码
                    var containerCode = request.ContainerCode;
                    if (string.IsNullOrEmpty(containerCode))
                    {
                        throw new Exception("请输入底板编码.");
                    }
                }
                #endregion

                #region Lot 批号(上条码)6开头12位
                if (string.IsNullOrEmpty(request.LotBatch))
                {
                    throw new Exception("批号(上条码)不能为空.");
                }

                var lotBatchReg = new Regex(@"^6(\d+)$");
                if (!lotBatchReg.IsMatch(request.LotBatch))
                {
                    throw new Exception("批号(上条码)必须以6开头且12位数字组成.");
                }

                lotBatchReg = new Regex(@"^[0-9]{12}$");
                if (!lotBatchReg.IsMatch(request.LotBatch))
                {
                    throw new Exception("批号(上条码)必须以6开头且12位数字组成.");
                }
                #endregion

                #region 扫条码时间
                //扫下条码时间
                var travellerDate = DateTime.Now.AddMinutes(-5).ToString("yyyy-MM-dd HH:mm:ss");
                //验证是否为空
                if (!string.IsNullOrEmpty(request.TravellerDate))
                {
                    travellerDate = request.TravellerDate;
                }
                #endregion

                #region Part Num 料号
                if (string.IsNullOrEmpty(request.PartNum))
                {
                    throw new Exception("料号不能为空.");
                }
                #endregion

                #region Heap Number 叠合次数号
                if (string.IsNullOrEmpty(request.HeapNumber))
                {
                    throw new Exception("叠合次数号不能为空.");
                }
                #endregion

                #region Press Program 压合程式
                if (string.IsNullOrEmpty(request.PressProgram))
                {
                    throw new Exception("压合程式不能为空.");
                }

                //键值
                var dictionarys = GetDictionary();

                var newDictionarys = new List<Dictionary>();

                if (dictionarys != null && dictionarys.Any())
                {
                    //var pressProgram = request.PressProgram.Replace("_", "").Replace("-", "").Replace(" ", "").ToUpper();

                    //var dictionary = dictionarys.FirstOrDefault(c => c.Type == (int)DictionaryFiled.压合程式 && c.Name.Replace("_", "").Replace("-", "").Replace(" ", "").ToUpper() == pressProgram);
                    //if (dictionary == null)
                    //{
                    //    throw new Exception("压合程式转换有误.");
                    //}
                    //else
                    //{
                    //    request.PressProgramFull = dictionary.Value;
                    //}
                    var pressProgram = request.PressProgram.Replace("_", "").Replace("-", "").Replace(" ", "").ToUpper();

                    var dictionary = dictionarys.FirstOrDefault(c => c.Type == (int)DictionaryFiled.压合程式 && c.Name.Replace("_", "").Replace("-", "").Replace(" ", "").ToUpper() == pressProgram);
                    if (dictionary == null)
                    {
                        throw new Exception("压合程式转换有误.");
                    }
                    else
                    {
                        request.PressProgramFull = dictionary.Value;
                    }
                }
                else
                {
                    throw new Exception("Dictionary数据为空.");
                }
                #endregion

                //转换为数组
                var arr = request.LowerBarCode.Split("|");

                if (arr.Length < 4)
                {
                    throw new Exception("扫码内容格式有误.");
                }

                //铜箔
                var cuFoilNum = arr[0];
                //PP1
                var ppRCFPartNum1 = arr[1];
                //PP2
                var ppRCFPartNum2 = arr[2];
                #endregion

                if (request.MaterialType == "Cu_pp")
                {
                    //416278|414930|000000|EMC21|LA12|0.4010
                    //416278|414930|414931|EMC21|LA12|0.4010
                    #region Cu_pp

                    #region 铜箔编号
                    if (string.IsNullOrEmpty(cuFoilNum))
                    {
                        throw new Exception("铜箔编号由6位数字组成.");

                    }
                    var cuFoilNumReg = new Regex(@"^000000");
                    if (cuFoilNumReg.IsMatch(cuFoilNum))
                    {
                        throw new Exception("铜箔编号有误.");
                    }

                    cuFoilNumReg = new Regex(@"^[0-9]{6}$");
                    if (!cuFoilNumReg.IsMatch(cuFoilNum))
                    {
                        throw new Exception("铜箔编号由6位数字组成.");
                    }

                    if(request.CuFoilNum != cuFoilNum)
                    {
                        throw new Exception($"铜箔编号与流程卡信息不一致,实际为{cuFoilNum}.");
                    }
                    #endregion

                    #region 铜箔批号
                    if (string.IsNullOrEmpty(request.CuFoilBatchNum))
                    {
                        throw new Exception("铜箔批号不能为空.");
                    }
                    #endregion

                    #region 铜箔有效期
                    if (string.IsNullOrEmpty(request.CuFoilExpire))
                    {
                        throw new Exception("铜箔有效期不能为空.");
                    }

                    //验证是否日期格式
                    if (!DateUtil.IsDateTime(request.CuFoilExpire))
                    {
                        throw new Exception(@$"铜箔有效期[{request.CuFoilExpire}]格式有误.");
                    }
                    //当前时期
                    var nowDate = DateTime.Now;
                    //输入时期
                    var reqeustDate = Convert.ToDateTime(request.CuFoilExpire).Date;
                    //验证
                    if (reqeustDate.Date < nowDate)
                    {
                        throw new Exception("铜箔有效期必须大于当前时间.");
                    }
                    #endregion

                    #region pp 半固化片种类数
                    //半固化片种类数
                    var ppTypeNumbers = new List<int> { 0,1,2 };

                    var ppTypeNumber = request.PpTypeNumber;
                    if (!ppTypeNumbers.Any(item=>item == ppTypeNumber))
                    {
                        throw new Exception("半固化片种类数只能为0、1、2");
                    }
                    #endregion

                    #region 半固化片数量
                    var ppNumber = request.PpNumber;
                    if (ppNumber <= 0)
                    {
                        throw new Exception("半固化片数量不能为空.");
                    }
                    #endregion

                    #region pp1_1
                    // 零包OR整包
                    var postponedMaterialTypeArr = new List<int>()
                        {
                            (int)PostponedMaterialType.整包,
                            (int)PostponedMaterialType.零包
                        };

                    if (!postponedMaterialTypeArr.Contains(request.PostponedMaterialType1_1))
                    {
                        throw new Exception("请选择零包OR整包1_1.");
                    }
                    //Package Num包号1_1
                    if (string.IsNullOrEmpty(request.PackageNum1_1))
                    {
                        throw new Exception("Package Num包号1_1不能为空.");
                    }
                    //PP/PCF 料号1_1
                    if (string.IsNullOrEmpty(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("Package Num料号1_1不能为空.");
                    }

                    var ppPcfPartNum1_1Reg = new Regex(@"^000000");
                    if (ppPcfPartNum1_1Reg.IsMatch(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("PP/PCF 料号1_1格式有误.");
                    }

                    ppPcfPartNum1_1Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppPcfPartNum1_1Reg.IsMatch(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("PP/PCF 料号1_1由6位数字组成.");
                    }

                    if(ppRCFPartNum1 != request.PpPcfPartNum1_1)
                    {
                        throw new Exception($"PP/PCF 料号1_1与流程卡信息不一致,实际为{ppRCFPartNum1}.");
                    }
                    //PP/PCF 批号1_1
                    if (string.IsNullOrEmpty(request.PpPcfBatchNum1_1))
                    {
                        throw new Exception("PP/PCF 批号1_1不能为空.");
                    }

                    //PP/PCF 有效期1_1
                    if (string.IsNullOrEmpty(request.PpPcfExpire1_1))
                    {
                        throw new Exception("PP/PCF 有效期1_1不能为空.");
                    }

                    //验证是否日期格式
                    if (!DateUtil.IsDateTime(request.PpPcfExpire1_1))
                    {
                        throw new Exception(@$"PP/PCF 有效期1_1[{request.PpPcfExpire1_1}]格式有误.");
                    }

                    //当前时期
                    var nowDate1_1 = DateTime.Now;
                    //输入时期
                    var reqeustDate1_1 = Convert.ToDateTime(request.PpPcfExpire1_1).Date;
                    //验证
                    if (reqeustDate1_1.Date < nowDate1_1)
                    {
                        throw new Exception("PP/PCF 有效期1_1必须大于当前时间.");
                    }

                    //Postponed Material延期材料1_1
                    if (request.PostponedMaterial1_1 <= 0)
                    {
                        throw new Exception("Postponed Material延期材料1_1不能为空.");
                    }
                    #endregion

                    #region pp1_2
                    // 零包OR整包
                    if (postponedMaterialTypeArr.Contains(request.PostponedMaterialType1_2))
                    {
                        //Package Num包号1_2
                        if (string.IsNullOrEmpty(request.PackageNum1_2))
                        {
                            throw new Exception("Package Num包号1_2不能为空.");
                        }
                        //PP/PCF 料号1_2
                        var ppPcfPartNum1_2Reg = new Regex(@"^000000");
                        if (ppPcfPartNum1_2Reg.IsMatch(request.PpPcfPartNum1_2))
                        {
                            throw new Exception("PP/PCF 料号1_2格式有误.");
                        }

                        ppPcfPartNum1_2Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppPcfPartNum1_2Reg.IsMatch(request.PpPcfPartNum1_2))
                        {
                            throw new Exception("PP/PCF 料号1_2由6位数字组成.");
                        }

                        if (ppRCFPartNum1 != request.PpPcfPartNum1_2)
                        {
                            throw new Exception($"PP/PCF 料号1_2与流程卡信息不一致,实际为{ppRCFPartNum1}.");
                        }

                        //PP/PCF 批号1_2
                        if (string.IsNullOrEmpty(request.PpPcfBatchNum1_2))
                        {
                            throw new Exception("PP/PCF 批号1_2不能为空.");
                        }

                        //PP/PCF 有效期1_2
                        if (string.IsNullOrEmpty(request.PpPcfExpire1_2))
                        {
                            throw new Exception("PP/PCF 有效期1_2不能为空.");
                        }

                        //验证是否日期格式
                        if (!DateUtil.IsDateTime(request.PpPcfExpire1_2))
                        {
                            throw new Exception(@$"PP/PCF 有效期1_2[{request.PpPcfExpire1_2}]格式有误.");
                        }

                        //当前时期
                        var nowDate1_2 = DateTime.Now;
                        //输入时期
                        var reqeustDate1_2 = Convert.ToDateTime(request.PpPcfExpire1_2).Date;
                        //验证
                        if (reqeustDate1_2.Date < nowDate1_2)
                        {
                            throw new Exception("PP/PCF 有效期1_2必须大于当前时间.");
                        }

                        //Postponed Material延期材料1_2
                        if (request.PostponedMaterial1_2 <= 0)
                        {
                            throw new Exception("Postponed Material延期材料1_2不能为空.");
                        }
                    }

                    #endregion

                    #region pp2_1
                    var ppRCFPartNum2Reg = new Regex(@"^000000");
                    if (!ppRCFPartNum2Reg.IsMatch(ppRCFPartNum2))
                    {
                        //Package Num包号2_1
                        if (string.IsNullOrEmpty(request.PackageNum2_1))
                        {
                            throw new Exception("Package Num包号2_1不能为空.");
                        }
                        //PP/PCF 料号2_1
                        if (string.IsNullOrEmpty(request.PpPcfPartNum2_1))
                        {
                            throw new Exception("Package Num包号2_1不能为空.");
                        }

                        var ppPcfPartNum2_1Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppPcfPartNum2_1Reg.IsMatch(request.PpPcfPartNum2_1))
                        {
                            throw new Exception("PP/PCF 料号2_1由6位数字组成.");
                        }
                        if (ppRCFPartNum2 != request.PpPcfPartNum2_1)
                        {
                            throw new Exception($"PP/PCF 料号2_1与流程卡信息不一致,实际为{ppRCFPartNum2}.");
                        }
                        //PP/PCF 批号2_1
                        if (string.IsNullOrEmpty(request.PpPcfBatchNum2_1))
                        {
                            throw new Exception("PP/PCF 批号2_1不能为空.");
                        }
                        //PP/PCF 有效期2_1
                        if (string.IsNullOrEmpty(request.PpPcfExpire2_1))
                        {
                            throw new Exception("PP/PCF 有效期2_1不能为空.");
                        }

                        //验证是否日期格式
                        if (!DateUtil.IsDateTime(request.PpPcfExpire2_1))
                        {
                            throw new Exception(@$"PP/PCF 有效期2_1[{request.PpPcfExpire2_1}]格式有误.");
                        }

                        //当前时期
                        var nowDate2_1 = DateTime.Now;
                        //输入时期
                        var reqeustDate2_1 = Convert.ToDateTime(request.PpPcfExpire2_1).Date;
                        //验证
                        if (reqeustDate2_1.Date < nowDate2_1)
                        {
                            throw new Exception("PP/PCF 有效期2_1必须大于当前时间.");
                        }

                        //Postponed Material延期材料2_1
                        if (request.PostponedMaterial2_1 <= 0)
                        {
                            throw new Exception("Postponed Material延期材料1_2不能为空.");
                        }
                    }
                    #endregion

                    #region pp2_2
                    // 零包OR整包
                    if (postponedMaterialTypeArr.Contains(request.PostponedMaterialType2_2))
                    {
                        //Package Num包号2_2
                        if (string.IsNullOrEmpty(request.PackageNum2_2))
                        {
                            throw new Exception("Package Num包号2_2不能为空.");
                        }
                        //PP/PCF 料号2_2
                        if (string.IsNullOrEmpty(request.PpPcfPartNum2_2))
                        {
                            throw new Exception("PP/PCF 料号2_2不能为空.");
                        }

                        var ppPcfPartNum2_2Reg = new Regex(@"^000000");
                        if (ppPcfPartNum2_2Reg.IsMatch(request.PpPcfPartNum2_2))
                        {
                            throw new Exception("PP/PCF 料号2_2格式有误.");
                        }

                        ppPcfPartNum2_2Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppPcfPartNum2_2Reg.IsMatch(request.PpPcfPartNum2_2))
                        {
                            throw new Exception("PP/PCF 料号2_2由6位数字组成.");
                        }

                        if (ppRCFPartNum2 != request.PpPcfPartNum2_2)
                        {
                            throw new Exception($"PP/PCF 料号2_2与流程卡信息不一致,实际为{ppRCFPartNum2}.");
                        }

                        //PP/PCF 批号2_2
                        if (string.IsNullOrEmpty(request.PpPcfBatchNum2_2))
                        {
                            throw new Exception("PP/PCF 批号2_2不能为空.");
                        }

                        //PP/PCF 有效期2_2
                        if (string.IsNullOrEmpty(request.PpPcfExpire2_2))
                        {
                            throw new Exception("PP/PCF 有效期2_2不能为空.");
                        }

                        //验证是否日期格式
                        if (!DateUtil.IsDateTime(request.PpPcfExpire2_2))
                        {
                            throw new Exception(@$"PP/PCF 有效期2_2[{request.PpPcfExpire2_2}]格式有误.");
                        }

                        //当前时期
                        var nowDate2_2 = DateTime.Now;
                        //输入时期
                        var reqeustDate2_2 = Convert.ToDateTime(request.PpPcfExpire2_2).Date;
                        //验证
                        if (reqeustDate2_2.Date < nowDate2_2)
                        {
                            throw new Exception("PP/PCF 有效期2_2必须大于当前时间.");
                        }

                        //Postponed Material延期材料2_2
                        if (request.PostponedMaterial2_2 <= 0)
                        {
                            throw new Exception("Postponed Material延期材料2_2不能为空.");
                        }
                    }
                    #endregion

                    #endregion
                }
                else if (request.MaterialType == "RCF")
                {
                    //000000|413251|000000|Long_dIMPLE18|LA3|0.2942
                    #region RCF

                    #region pp 半固化片种类数
                    //半固化片种类数
                    var ppTypeNumbers = new List<int> { 0, 1, 2 };

                    var ppTypeNumber = request.PpTypeNumber;
                    if (!ppTypeNumbers.Any(item => item == ppTypeNumber))
                    {
                        throw new Exception("半固化片种类数只能为0、1、2");
                    }
                    #endregion

                    #region 半固化片数量
                    var ppNumber = request.PpNumber;
                    if (!ppNumber.HasValue)
                    {
                        throw new Exception("请输入半固化片数量.");
                    }
                    #endregion

                    #region pp1_1
                    // 零包OR整包
                    var postponedMaterialTypeArr = new List<int>()
                        {
                            (int)PostponedMaterialType.整包,
                            (int)PostponedMaterialType.零包
                        };

                    if (!postponedMaterialTypeArr.Contains(request.PostponedMaterialType1_1))
                    {
                        throw new Exception("请选择零包OR整包1_1.");
                    }
                    //Package Num包号1_1
                    if (string.IsNullOrEmpty(request.PackageNum1_1))
                    {
                        throw new Exception("Package Num包号1_1不能为空.");
                    }
                    //PP/PCF 料号1_1
                    if (string.IsNullOrEmpty(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("PP/PCF 料号1_1不能为空.");

                    }
                    var ppPcfPartNum1_1Reg = new Regex(@"^000000");
                    if (ppPcfPartNum1_1Reg.IsMatch(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("PP/PCF 料号1_1格式有误.");
                    }

                    ppPcfPartNum1_1Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppPcfPartNum1_1Reg.IsMatch(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("PP/PCF 料号1_1由6位数字组成.");
                    }

                    if (ppRCFPartNum1 != request.PpPcfPartNum1_1)
                    {
                        throw new Exception($"PP/PCF 料号1_1与流程卡信息不一致,实际为{ppRCFPartNum1}.");
                    }
                    //PP/PCF 批号1_1
                    if (string.IsNullOrEmpty(request.PpPcfBatchNum1_1))
                    {
                        throw new Exception("PP/PCF 批号1_1不能为空.");
                    }

                    //PP/PCF 有效期1_1
                    if (string.IsNullOrEmpty(request.PpPcfExpire1_1))
                    {
                        throw new Exception("PP/PCF 有效期1_1不能为空.");
                    }

                    //验证是否日期格式
                    if (!DateUtil.IsDateTime(request.PpPcfExpire1_1))
                    {
                        throw new Exception(@$"PP/PCF 有效期1_1[{request.PpPcfExpire1_1}]格式有误.");
                    }

                    //当前时期
                    var nowDate1_1 = DateTime.Now;
                    //输入时期
                    var reqeustDate1_1 = Convert.ToDateTime(request.PpPcfExpire1_1).Date;
                    //验证
                    if (reqeustDate1_1.Date < nowDate1_1)
                    {
                        throw new Exception("PP/PCF 有效期1_1必须大于当前时间.");
                    }

                    //Postponed Material延期材料1_1
                    if (request.PostponedMaterial1_1 <= 0)
                    {
                        throw new Exception("Postponed Material延期材料1_1不能为空.");
                    }
                    #endregion

                    #region pp1_2
                    // 零包OR整包
                    if (postponedMaterialTypeArr.Contains(request.PostponedMaterialType1_2))
                    {
                        //Package Num包号1_2
                        if (string.IsNullOrEmpty(request.PackageNum1_2))
                        {
                            throw new Exception("Package Num包号1_2不能为空.");
                        }
                        //PP/PCF 料号1_2
                        if (string.IsNullOrEmpty(request.PpPcfPartNum1_2))
                        {
                            throw new Exception("PP/PCF 料号1_1不能为空.");
                        }

                        var ppPcfPartNum1_2Reg = new Regex(@"^000000");
                        if (ppPcfPartNum1_2Reg.IsMatch(request.PpPcfPartNum1_2))
                        {
                            throw new Exception("PP/PCF 料号1_2格式有误.");
                        }

                        ppPcfPartNum1_2Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppPcfPartNum1_2Reg.IsMatch(request.PpPcfPartNum1_2))
                        {
                            throw new Exception("PP/PCF 料号1_2由6位数字组成.");
                        }

                        if (ppRCFPartNum1 != request.PpPcfPartNum1_2)
                        {
                            throw new Exception($"PP/PCF 料号1_2与流程卡信息不一致,实际为{ppRCFPartNum1}.");
                        }

                        //PP/PCF 批号1_2
                        if (string.IsNullOrEmpty(request.PpPcfBatchNum1_2))
                        {
                            throw new Exception("PP/PCF 批号1_2不能为空.");
                        }

                        //PP/PCF 有效期1_2
                        if (string.IsNullOrEmpty(request.PpPcfExpire1_2))
                        {
                            throw new Exception("PP/PCF 有效期1_2不能为空.");
                        }

                        //验证是否日期格式
                        if (!DateUtil.IsDateTime(request.PpPcfExpire1_2))
                        {
                            throw new Exception(@$"PP/PCF 有效期1_2[{request.PpPcfExpire1_2}]格式有误.");
                        }

                        //当前时期
                        var nowDate1_2 = DateTime.Now;
                        //输入时期
                        var reqeustDate1_2 = Convert.ToDateTime(request.PpPcfExpire1_2).Date;
                        //验证
                        if (reqeustDate1_2.Date < nowDate1_2)
                        {
                            throw new Exception("PP/PCF 有效期1_2必须大于当前时间.");
                        }

                        //Postponed Material延期材料1_2
                        if (request.PostponedMaterial1_2 <= 0)
                        {
                            throw new Exception("Postponed Material延期材料1_2不能为空.");
                        }
                    }

                    #endregion

                    #region pp2_1
                    var ppRCFPartNum2_1Reg = new Regex(@"^000000");
                    if (!ppRCFPartNum2_1Reg.IsMatch(ppRCFPartNum2))
                    {
                        //Package Num包号2_1
                        if (string.IsNullOrEmpty(request.PackageNum2_1))
                        {
                            throw new Exception("Package Num包号2_1不能为空.");
                        }
                        //PP/PCF 料号2_1
                        if (string.IsNullOrEmpty(request.PpPcfPartNum2_1))
                        {
                            throw new Exception("Package Num料号2_1不能为空.");
                        }

                        var ppPcfPartNum2_1Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppPcfPartNum2_1Reg.IsMatch(request.PpPcfPartNum2_1))
                        {
                            throw new Exception("PP/PCF 料号2_1由6位数字组成.");
                        }
                        if (ppRCFPartNum2 != request.PpPcfPartNum2_1)
                        {
                            throw new Exception($"PP/PCF 料号2_1与流程卡信息不一致,实际为{ppRCFPartNum2}.");
                        }
                        //PP/PCF 批号2_1
                        if (string.IsNullOrEmpty(request.PpPcfBatchNum2_1))
                        {
                            throw new Exception("PP/PCF 批号2_1不能为空.");
                        }
                        //PP/PCF 有效期2_1
                        if (string.IsNullOrEmpty(request.PpPcfExpire2_1))
                        {
                            throw new Exception("PP/PCF 有效期2_1不能为空.");
                        }

                        //验证是否日期格式
                        if (!DateUtil.IsDateTime(request.PpPcfExpire2_1))
                        {
                            throw new Exception(@$"PP/PCF 有效期2_1[{request.PpPcfExpire2_1}]格式有误.");
                        }

                        //当前时期
                        var nowDate2_1 = DateTime.Now;
                        //输入时期
                        var reqeustDate2_1 = Convert.ToDateTime(request.PpPcfExpire2_1).Date;
                        //验证
                        if (reqeustDate2_1.Date < nowDate2_1)
                        {
                            throw new Exception("PP/PCF 有效期2_1必须大于当前时间.");
                        }

                        //Postponed Material延期材料2_1
                        if (request.PostponedMaterial2_1 <= 0)
                        {
                            throw new Exception("Postponed Material延期材料2_1不能为空.");
                        }
                    }
                    //PPRCFPartNum2
                    #endregion

                    #endregion
                }
                else if (request.MaterialType == "OnlyPP")
                {
                    //000000|413251|000000|Long_dIMPLE18|LA3|0.2942
                    #region OnlyPP

                    #region pp 半固化片种类数
                    //半固化片种类数
                    var ppTypeNumbers = new List<int> { 0, 1, 2 };

                    var ppTypeNumber = request.PpTypeNumber;
                    if (!ppTypeNumbers.Any(item => item == ppTypeNumber))
                    {
                        throw new Exception("半固化片种类数只能为0、1、2");
                    }
                    #endregion

                    #region 半固化片数量
                    var ppNumber = request.PpNumber;
                    if (!ppNumber.HasValue)
                    {
                        throw new Exception("请输入半固化片数量.");
                    }
                    #endregion

                    #region pp1_1
                    // 零包OR整包
                    var postponedMaterialTypeArr = new List<int>()
                        {
                            (int)PostponedMaterialType.整包,
                            (int)PostponedMaterialType.零包
                        };

                    if (!postponedMaterialTypeArr.Contains(request.PostponedMaterialType1_1))
                    {
                        throw new Exception("请选择零包OR整包1_1.");
                    }
                    //Package Num包号1_1
                    if (string.IsNullOrEmpty(request.PackageNum1_1))
                    {
                        throw new Exception("Package Num包号1_1不能为空.");
                    }
                    //PP/PCF 料号1_1
                    if (string.IsNullOrEmpty(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("PP/PCF 料号1_1不能为空.");
                    }

                    var ppPcfPartNum1_1Reg = new Regex(@"^000000");
                    if (ppPcfPartNum1_1Reg.IsMatch(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("PP/PCF 料号1_1格式有误.");
                    }

                    ppPcfPartNum1_1Reg = new Regex(@"^[0-9]{6}$");
                    if (!ppPcfPartNum1_1Reg.IsMatch(request.PpPcfPartNum1_1))
                    {
                        throw new Exception("PP/PCF 料号1_1由6位数字组成.");
                    }

                    if (ppRCFPartNum1 != request.PpPcfPartNum1_1)
                    {
                        throw new Exception($"PP/PCF 料号1_1与流程卡信息不一致,实际为{ppRCFPartNum1}.");
                    }
                    //PP/PCF 批号1_1
                    if (string.IsNullOrEmpty(request.PpPcfBatchNum1_1))
                    {
                        throw new Exception("PP/PCF 批号1_1不能为空.");
                    }

                    //PP/PCF 有效期1_1
                    if (string.IsNullOrEmpty(request.PpPcfExpire1_1))
                    {
                        throw new Exception("PP/PCF 有效期1_1不能为空.");
                    }

                    //验证是否日期格式
                    if (!DateUtil.IsDateTime(request.PpPcfExpire1_1))
                    {
                        throw new Exception(@$"PP/PCF 有效期1_1[{request.PpPcfExpire1_1}]格式有误.");
                    }

                    //当前时期
                    var nowDate1_1 = DateTime.Now;
                    //输入时期
                    var reqeustDate1_1 = Convert.ToDateTime(request.PpPcfExpire1_1).Date;
                    //验证
                    if (reqeustDate1_1.Date < nowDate1_1)
                    {
                        throw new Exception("PP/PCF 有效期1_1必须大于当前时间.");
                    }

                    //Postponed Material延期材料1_1
                    if (request.PostponedMaterial1_1 <= 0)
                    {
                        throw new Exception("Postponed Material延期材料1_1不能为空.");
                    }
                    #endregion

                    #region pp1_2
                    // 零包OR整包
                    if (postponedMaterialTypeArr.Contains(request.PostponedMaterialType1_2))
                    {
                        //Package Num包号1_2
                        if (string.IsNullOrEmpty(request.PackageNum1_2))
                        {
                            throw new Exception("Package Num包号1_2不能为空.");
                        }
                        //PP/PCF 料号1_2
                        if (string.IsNullOrEmpty(request.PpPcfPartNum1_2))
                        {
                            throw new Exception("PP/PCF 料号1_1不能为空.");
                        }

                        var ppPcfPartNum1_2Reg = new Regex(@"^000000");
                        if (ppPcfPartNum1_2Reg.IsMatch(request.PpPcfPartNum1_2))
                        {
                            throw new Exception("PP/PCF 料号1_2格式有误.");
                        }

                        ppPcfPartNum1_2Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppPcfPartNum1_2Reg.IsMatch(request.PpPcfPartNum1_2))
                        {
                            throw new Exception("PP/PCF 料号1_2由6位数字组成.");
                        }

                        if (ppRCFPartNum1 != request.PpPcfPartNum1_2)
                        {
                            throw new Exception($"PP/PCF 料号1_2与流程卡信息不一致,实际为{ppRCFPartNum1}.");
                        }

                        //PP/PCF 批号1_2
                        if (string.IsNullOrEmpty(request.PpPcfBatchNum1_2))
                        {
                            throw new Exception("PP/PCF 批号1_2不能为空.");
                        }

                        //PP/PCF 有效期1_2
                        if (string.IsNullOrEmpty(request.PpPcfExpire1_2))
                        {
                            throw new Exception("PP/PCF 有效期1_2不能为空.");
                        }

                        //验证是否日期格式
                        if (!DateUtil.IsDateTime(request.PpPcfExpire1_2))
                        {
                            throw new Exception(@$"PP/PCF 有效期1_2[{request.PpPcfExpire1_2}]格式有误.");
                        }

                        //当前时期
                        var nowDate1_2 = DateTime.Now;
                        //输入时期
                        var reqeustDate1_2 = Convert.ToDateTime(request.PpPcfExpire1_2).Date;
                        //验证
                        if (reqeustDate1_2.Date < nowDate1_2)
                        {
                            throw new Exception("PP/PCF 有效期1_2必须大于当前时间.");
                        }

                        //Postponed Material延期材料1_2
                        if (request.PostponedMaterial1_2 <= 0)
                        {
                            throw new Exception("Postponed Material延期材料1_2不能为空.");
                        }
                    }

                    #endregion

                    #region pp2_1
                    var ppRCFPartNum2_1Reg = new Regex(@"^000000");
                    if (!ppRCFPartNum2_1Reg.IsMatch(ppRCFPartNum2))
                    {
                        // 零包OR整包
                        if (!postponedMaterialTypeArr.Contains(request.PostponedMaterialType2_1))
                        {
                            throw new Exception("请选择零包OR整包2_1.");
                        }
                        //Package Num包号2_1
                        if (string.IsNullOrEmpty(request.PackageNum2_1))
                        {
                            throw new Exception("Package Num包号2_1不能为空.");
                        }
                        //PP/PCF 料号2_1
                        if (string.IsNullOrEmpty(request.PpPcfPartNum2_1))
                        {
                            throw new Exception("Package Num料号2_1不能为空.");
                        }

                        var ppPcfPartNum2_1Reg = new Regex(@"^[0-9]{6}$");
                        if (!ppPcfPartNum2_1Reg.IsMatch(request.PpPcfPartNum2_1))
                        {
                            throw new Exception("PP/PCF 料号2_1由6位数字组成.");
                        }
                        if (ppRCFPartNum2 != request.PpPcfPartNum2_1)
                        {
                            throw new Exception($"PP/PCF 料号2_1与流程卡信息不一致,实际为{ppRCFPartNum2}.");
                        }
                        //PP/PCF 批号2_1
                        if (string.IsNullOrEmpty(request.PpPcfBatchNum2_1))
                        {
                            throw new Exception("PP/PCF 批号2_1不能为空.");
                        }
                        //PP/PCF 有效期2_1
                        if (string.IsNullOrEmpty(request.PpPcfExpire2_1))
                        {
                            throw new Exception("PP/PCF 有效期2_1不能为空.");
                        }

                        //验证是否日期格式
                        if (!DateUtil.IsDateTime(request.PpPcfExpire2_1))
                        {
                            throw new Exception(@$"PP/PCF 有效期2_1[{request.PpPcfExpire2_1}]格式有误.");
                        }

                        //当前时期
                        var nowDate2_1 = DateTime.Now;
                        //输入时期
                        var reqeustDate2_1 = Convert.ToDateTime(request.PpPcfExpire2_1).Date;
                        //验证
                        if (reqeustDate2_1.Date < nowDate2_1)
                        {
                            throw new Exception("PP/PCF 有效期2_1必须大于当前时间.");
                        }

                        //Postponed Material延期材料2_1
                        if (request.PostponedMaterial2_1 <= 0)
                        {
                            throw new Exception("Postponed Material延期材料1_2不能为空.");
                        }
                    }
                    //PPRCFPartNum2
                    #endregion

                    #endregion
                }
                else if (request.MaterialType == "GE02/CUSHI")
                {
                    //000000|000000|000000|Long_dIMPLE18|LA3|0.2942
                    #region GE02/CUSHI

                    #region pp 半固化片种类数
                    //半固化片种类数
                    var ppTypeNumbers = new List<int> { 0, 1, 2 };

                    var ppTypeNumber = request.PpTypeNumber;
                    if (!ppTypeNumbers.Any(item => item == ppTypeNumber))
                    {
                        throw new Exception("半固化片种类数只能为0、1、2");
                    }
                    #endregion

                    #region 半固化片数量
                    var ppNumber = request.PpNumber;
                    if (!ppNumber.HasValue)
                    {
                        throw new Exception("请输入半固化片数量.");
                    }
                    #endregion

                    #endregion
                }
                else if(request.MaterialType == "Only_cu")
                {
                    #region Only_cu

                    #region pp 半固化片种类数
                    //半固化片种类数
                    var ppTypeNumbers = new List<int> { 0, 1, 2 };

                    var ppTypeNumber = request.PpTypeNumber;
                    if (!ppTypeNumbers.Any(item => item == ppTypeNumber))
                    {
                        throw new Exception("半固化片种类数只能为0、1、2");
                    }
                    #endregion

                    #region 半固化片数量
                    var ppNumber = request.PpNumber;
                    if (!ppNumber.HasValue)
                    {
                        throw new Exception("请输入半固化片数量.");
                    }
                    #endregion

                    #endregion
                }
                else
                {
                    throw new Exception("材料类型有误.");
                }

                #region 低部

                #region Book Buildup Structure满本结构
                if (string.IsNullOrEmpty(request.BookBuildupStructure))
                {
                    throw new Exception("满本结构不能为空.");
                }
                #endregion

                #region 1.5mm Plate 垫厚钢板数
                if (string.IsNullOrEmpty(request.PlateNum))
                {
                    throw new Exception("垫厚钢板数不能为空.");
                }

                var plateNumReg = new Regex(@"^[+]{0,1}(\d+)$");
                if (!plateNumReg.IsMatch(request.PlateNum))
                {
                    throw new Exception("垫厚钢板数介于0~20正整数.");
                }

                var plateNum = Convert.ToInt32(request.PlateNum);

                if (plateNum < 0 || plateNum > 20)
                {
                    throw new Exception("垫厚钢板数介于(0~20正整数).");
                }
                #endregion

                #region Panel Quan 板数
                if (string.IsNullOrEmpty(request.PanelQuan))
                {
                    throw new Exception("板数介于不能为空.");
                }

                var panelQuanReg = new Regex(@"^[1-9]\d*$");
                if (!panelQuanReg.IsMatch(request.PanelQuan))
                {
                    throw new Exception("板数介于1~30整数.");
                }

                var panelQuan = Convert.ToInt32(request.PanelQuan);

                if (panelQuan <= 0 || panelQuan > 30)
                {
                    throw new Exception("板数介于1~30整数.");
                }

                //获取配置
                var configs = GetConfig();

                #region 叠板片数限制
                //叠板片数
                var heapNumber = 0;

                var heapSetUpList = configs.Where(c => c.Type == (int)SettingType.叠板片数设定).ToList();
                if (heapSetUpList != null && heapSetUpList.Any())
                {
                    //批号
                    var heapSetUpBatch = heapSetUpList.FirstOrDefault(c => c.PartNo == request.PartNum && c.LotNo == request.LotBatch && c.Cycle == request.HeapNumber);
                    if (heapSetUpBatch != null)
                    {
                        int.TryParse(heapSetUpBatch.Value, out heapNumber);
                    }
                    else
                    {
                        //获取配置
                        var heapSetUp = heapSetUpList.FirstOrDefault(c => c.PartNo == request.PartNum && c.Cycle == request.HeapNumber);
                        //验证
                        if (heapSetUp != null)
                        {
                            int.TryParse(heapSetUp.Value, out heapNumber);
                        }
                        else
                        {
                            var _partNum = "";
                            //长度数组
                            var lengths = new List<int>() { 6, 7, 8 };
                            //长度验证
                            if (lengths.Any(item => item == request.PartNum.Length))
                            {
                                _partNum = request.PartNum.Substring(0, request.PartNum.Length - 1);
                            }
                            else
                            {
                                _partNum = request.PartNum;
                            }

                            //获取配置
                            heapSetUp = heapSetUpList.FirstOrDefault(c => c.PartNo.Contains(_partNum) && c.Cycle == request.HeapNumber);
                            if (heapSetUp != null)
                            {
                                int.TryParse(heapSetUp.Value, out heapNumber);
                            }
                        }
                    }
                }

                if (heapNumber > 0 && panelQuan > heapNumber)
                {
                    throw new Exception($"Panel Quan 板数必须小于或等于{heapNumber}.");
                }
                #endregion

                #endregion

                #region Secion Quan 含切片的板数
                if (string.IsNullOrEmpty(request.SecionQuan))
                {
                    throw new Exception("含切片的板数不能为空.");
                }

                var secionQuanReg = new Regex(@"^[0-9]\d*$");
                if (!secionQuanReg.IsMatch(request.SecionQuan))
                {
                    throw new Exception("含切片的板数介于0~30整数");
                }

                var secionQuan = 0;

                int.TryParse(request.SecionQuan, out secionQuan);

                if (secionQuan < 0 || secionQuan > 30)
                {
                    throw new Exception("含切片的板数介于0~30整数)");
                }
                #endregion

                #region Alpha Board Stay Time棕化停留时间
                if (string.IsNullOrEmpty(request.AlphaBoardStayTime))
                {
                    throw new Exception("棕化停留时间不能为空.");
                }

                var alphaBoardStayTimeReg = new Regex(@"^[+]{0,1}(\d+)$");
                if (!alphaBoardStayTimeReg.IsMatch(request.AlphaBoardStayTime))
                {
                    throw new Exception("棕化停留时间只能输入正整数.");
                }

                var alphaBoardStayTime = Convert.ToInt32(request.AlphaBoardStayTime);
                if (alphaBoardStayTime > 72)
                {
                    throw new Exception("棕化停留时间小于72小时.");
                }
                #endregion

                #region Stopper Quality 防滑质量
                if (request.StopperQuality <= 0)
                {
                    throw new Exception("请选择防滑质量.");
                }
                #endregion

                #region Perpreg Surface Quality 表面质量
                if (request.PerpregSurfaceQuality <= 0)
                {
                    throw new Exception("请选择表面质量.");
                }
                #endregion

                #region 14 Pcs Kraft Quality 14张牛皮纸数量
                if (request.PcsKraftQuality <= 0)
                {
                    throw new Exception("请选择14张牛皮纸数量.");
                }
                #endregion

                #region Inner Core Quality 内层芯板质量
                if (request.InnerCoreQuality <= 0)
                {
                    throw new Exception("请选择内层芯板质量.");
                }
                #endregion

                #region Copper Foil Quality 铜箔质量
                if (request.CopperFoilQuality <= 0)
                {
                    throw new Exception("请选择铜箔质量.");
                }
                #endregion

                #region Steel Plate Quality 纲板质量
                if (request.SteelPlateQuality <= 0)
                {
                    throw new Exception("请选择纲板质量.");
                }
                #endregion
                

                #region 异常钢板数量
                if (string.IsNullOrEmpty(request.AbnormalSteelPlateQuantity))
                {
                    throw new Exception("异常钢板数量不能为空.");
                }

                var abnormalSteelPlateQuantityReg = new Regex(@"^[+]{0,1}(\d+)$");
                if (!abnormalSteelPlateQuantityReg.IsMatch(request.AbnormalSteelPlateQuantity))
                {
                    throw new Exception("异常钢板数量只能输入正整数");
                }
                #endregion

                #endregion

                #endregion

                #region 限制
                //料号
                var partNum = "";
                //长度数组
                var Lengths = new List<int>() { 6, 7, 8 };
                //长度验证
                if (Lengths.Any(item => item == request.PartNum.Length))
                {
                    partNum = request.PartNum.Substring(0, request.PartNum.Length - 1);
                }
                else
                {
                    partNum = request.PartNum;
                }

                #region 员工号限制
                var staffNumList = configs.Where(c => c.Type == (int)SettingType.员工号限制).ToList();
                if (staffNumList != null && staffNumList.Any())
                {
                    //批号
                    var staffNumBatch = staffNumList.FirstOrDefault(c => c.PartNo == request.PartNum && c.LotNo == request.LotBatch && c.Cycle == request.HeapNumber && c.Value == request.StaffNum);
                    if (staffNumBatch != null)
                    {
                        throw new Exception("此员工号限制使用.");
                    }
                    else
                    {
                        //获取配置
                        var staffNumConfig = staffNumList.FirstOrDefault(c => c.PartNo == request.PartNum && c.Cycle == request.HeapNumber && c.Value == request.StaffNum);
                        //验证
                        if (staffNumConfig != null)
                        {
                            throw new Exception("此员工号限制使用.");
                        }
                        else
                        {
                            //获取配置
                            staffNumConfig = staffNumList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == request.HeapNumber && c.Value == request.StaffNum);
                            if (staffNumConfig != null)
                            {
                                throw new Exception("此员工号限制使用.");
                            }
                        }
                    }
                }
                #endregion

                #region 产品限制
                var partNumList = configs.Where(c => c.Type == (int)SettingType.产品限制).ToList();
                if (partNumList != null && partNumList.Any())
                {
                    //批号
                    var partNumBatch = partNumList.FirstOrDefault(c => c.PartNo == request.PartNum && c.LotNo == request.LotBatch && c.Cycle == request.HeapNumber);
                    if (partNumBatch != null)
                    {
                        throw new Exception("此产品限制生产.");
                    }
                    else
                    {
                        //获取配置
                        var partNumConfig = partNumList.FirstOrDefault(c => c.PartNo == request.PartNum && c.Cycle == request.HeapNumber);
                        //验证
                        if (partNumConfig != null)
                        {
                            throw new Exception("此产品限制生产.");
                        }
                        else
                        {
                            //获取配置
                            partNumConfig = partNumList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == request.HeapNumber);
                            if (partNumConfig != null)
                            {
                                throw new Exception("此产品限制生产.");
                            }
                        }
                    }

                }
                #endregion

                #region 机台限制
                var equipmentCodeList = configs.Where(c => c.Type == (int)SettingType.机台限制).ToList();
                if (equipmentCodeList != null && equipmentCodeList.Any())
                {
                    //批号
                    var equipmentCodeBatch = equipmentCodeList.FirstOrDefault(c => c.PartNo == request.PartNum && c.LotNo == request.LotBatch && c.Cycle == request.HeapNumber && c.Value == user.EquipmentCode);
                    if (equipmentCodeBatch != null)
                    {
                        throw new Exception("此设备编码禁止使用.");
                    }
                    else
                    {
                        //获取配置
                        var equipmentCodeConfig = equipmentCodeList.FirstOrDefault(c => c.PartNo == request.PartNum && c.Cycle == request.HeapNumber && c.Value == user.EquipmentCode);
                        //验证
                        if (equipmentCodeConfig != null)
                        {
                            throw new Exception("此设备编码禁止使用.");
                        }
                        else
                        {
                            //获取配置
                            equipmentCodeConfig = equipmentCodeList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == request.HeapNumber && c.Value == user.EquipmentCode);
                            if (equipmentCodeConfig != null)
                            {
                                throw new Exception("此设备编码禁止使用.");
                            }
                        }
                    }
                }
                #endregion

                #region 材料限制

                #region 料号
                //材料料号数组
                var partNumLimitArray = new List<string>();
                //1_1
                if (!string.IsNullOrEmpty(request.PpPcfPartNum1_1))
                {
                    partNumLimitArray.Add(request.PpPcfPartNum1_1);
                }
                //1_2
                if (!string.IsNullOrEmpty(request.PpPcfPartNum1_2))
                {
                    partNumLimitArray.Add(request.PpPcfPartNum1_2);
                }
                //2_1
                if (!string.IsNullOrEmpty(request.PpPcfPartNum2_1))
                {
                    partNumLimitArray.Add(request.PpPcfPartNum2_1);
                }
                //2_2
                if (!string.IsNullOrEmpty(request.PpPcfPartNum2_2))
                {
                    partNumLimitArray.Add(request.PpPcfPartNum2_2);
                }

                
                var partNumLimitList = configs.Where(c => c.Type == (int)SettingType.材料限制 && c.FieldType == (int)MaterialFieldType.材料料号).ToList();
                if (partNumLimitList != null && partNumLimitList.Any())
                {
                    //批号
                    var partNumLimitBatch = partNumLimitList.FirstOrDefault(c => c.PartNo == request.PartNum && c.LotNo == request.LotBatch && c.Cycle == request.HeapNumber && partNumLimitArray.Contains(c.Value));
                    if (partNumLimitBatch != null)
                    {
                        throw new Exception("此PP料号禁止使用.");
                    }
                    else
                    {
                        //获取配置
                        var partNumLimitConfig = partNumLimitList.FirstOrDefault(c => c.PartNo == request.PartNum && c.Cycle == request.HeapNumber && partNumLimitArray.Contains(c.Value));
                        //验证
                        if (partNumLimitConfig != null)
                        {
                            throw new Exception("此PP料号禁止使用..");
                        }
                        else
                        {
                            //获取配置
                            partNumLimitConfig = partNumLimitList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == request.HeapNumber && partNumLimitArray.Contains(c.Value));
                            if (partNumLimitConfig != null)
                            {
                                throw new Exception("此PP料号禁止使用..");
                            }
                        }
                    }
                }
                #endregion

                #region 批号
                //材料料号数组
                var partBatchLimitArray = new List<string>();
                //1_1
                if (!string.IsNullOrEmpty(request.PpPcfBatchNum1_1))
                {
                    partBatchLimitArray.Add(request.PpPcfBatchNum1_1);
                }
                //1_2
                if (!string.IsNullOrEmpty(request.PpPcfBatchNum1_2))
                {
                    partBatchLimitArray.Add(request.PpPcfBatchNum1_2);
                }
                //2_1
                if (!string.IsNullOrEmpty(request.PpPcfBatchNum2_1))
                {
                    partBatchLimitArray.Add(request.PpPcfBatchNum2_1);
                }
                //2_2
                if (!string.IsNullOrEmpty(request.PpPcfBatchNum2_2))
                {
                    partBatchLimitArray.Add(request.PpPcfBatchNum2_2);
                }

                var partBatchLimitList = configs.Where(c => c.Type == (int)SettingType.材料限制 && c.FieldType == (int)MaterialFieldType.材料批号).ToList();
                if (partBatchLimitList != null && partBatchLimitList.Any())
                {
                    //批号
                    var partBatchLimitBatch = partBatchLimitList.FirstOrDefault(c => c.PartNo == request.PartNum && c.LotNo == request.LotBatch && c.Cycle == request.HeapNumber && partBatchLimitArray.Any(batch => batch == c.Value));
                    if (partBatchLimitBatch != null)
                    {
                        throw new Exception("此PP批号禁止使用.");
                    }
                    else
                    {
                        //获取配置
                        var partBatchLimitConfig = partBatchLimitList.FirstOrDefault(c => c.PartNo == request.PartNum && c.Cycle == request.HeapNumber && partBatchLimitArray.Any(batch => batch == c.Value));
                        //验证
                        if (partBatchLimitConfig != null)
                        {
                            throw new Exception("此PP批号禁止使用..");
                        }
                        else
                        {
                            //获取配置
                            partBatchLimitConfig = partBatchLimitList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.Cycle == request.HeapNumber && partBatchLimitArray.Any(batch => batch == c.Value));
                            if (partBatchLimitConfig != null)
                            {
                                throw new Exception("此PP批号禁止使用..");
                            }
                        }
                    }
                }
                #endregion

                #endregion

                #region 机台设定
                var machineSetUpList = configs.Where(c => c.Type == (int)SettingType.机台设定 && c.PartNo == request.PartNum && c.Cycle == request.HeapNumber).ToList();
                if (machineSetUpList != null && machineSetUpList.Any())
                {
                    if (!machineSetUpList.Any(c => c.Value == request.Account))
                    {
                        var sb = new StringBuilder();

                        machineSetUpList.ForEach(item => {
                            sb.Append(item.Value + "、");
                        });

                        throw new Exception($"<br><p>料号{request.PartNum}、叠合次数号:{request.HeapNumber},仅限于{sb.ToString().TrimEnd('、')}机台</p>");
                    }
                }
                else
                {
                    machineSetUpList = configs.Where(c => c.Type == (int)SettingType.机台设定 && c.PartNo.Contains(partNum) && c.Cycle == request.HeapNumber).ToList();
                    if (machineSetUpList != null && machineSetUpList.Any())
                    {
                        if (!machineSetUpList.Any(c => c.Value == request.Account))
                        {
                            var sb = new StringBuilder();

                            machineSetUpList.ForEach(item => {
                                sb.Append(item.Value + "、");
                            });

                            throw new Exception($"<br><p>料号{partNum}、叠合次数号:{request.HeapNumber},仅限于{sb.ToString().TrimEnd('、')}机台</p>");
                        }
                    }
                }
                #endregion

                #endregion

                #region 保存
                var iqs = new IQS()
                {
                    MachineCode = user.Account,
                    //PlntNum = int.Parse(request.PlntNum),
                    PlntNum = user.PlantNum,
                    StaffNum = request.StaffNum,
                    ShiftNum = request.ShiftNum,
                    //EquipmentCode = request.EquipmentCode,
                    EquipmentCode = user.EquipmentCode,
                    LotBatch = request.LotBatch,
                    PartNum = request.PartNum,
                    HeapNumber = request.HeapNumber,
                    MaterialType = request.MaterialType,
                    PressProgram = request.PressProgram,
                    PressProgramFull = request.PressProgramFull,
                    CuFoilNum = request.CuFoilNum,
                    CuFoilBatchNum = request.CuFoilBatchNum,
                    CuFoilExpire = request.CuFoilExpire,
                    PpTypeNumber = request.PpTypeNumber,
                    PpNumber = request.PpNumber.Value,
                    //1、整包
                    PostponedMaterialType1_1 = request.PostponedMaterialType1_1,

                    PackageNum1_1 = request.PackageNum1_1,
                    PpPcfPartNum1_1 = request.PpPcfPartNum1_1,
                    PpPcfBatchNum1_1 = request.PpPcfBatchNum1_1,
                    PpPcfExpire1_1 = request.PpPcfExpire1_1,
                    PostponedMaterial1_1 = request.PostponedMaterial1_1,
                    //1、零包
                    PostponedMaterialType1_2 = request.PostponedMaterialType1_2,

                    PackageNum1_2 = request.PackageNum1_2,
                    PpPcfPartNum1_2 = request.PpPcfPartNum1_2,
                    PpPcfBatchNum1_2 = request.PpPcfBatchNum1_2,
                    PpPcfExpire1_2 = request.PpPcfExpire1_2,
                    PostponedMaterial1_2 = request.PostponedMaterial1_2,

                    //2、整包
                    PostponedMaterialType2_1 = request.PostponedMaterialType2_1,

                    PackageNum2_1 = request.PackageNum2_1,
                    PpPcfPartNum2_1 = request.PpPcfPartNum2_1,
                    PpPcfBatchNum2_1 = request.PpPcfBatchNum2_1,
                    PpPcfExpire2_1 = request.PpPcfExpire2_1,
                    PostponedMaterial2_1 = request.PostponedMaterial2_1,
                    //2、零包
                    PostponedMaterialType2_2 = request.PostponedMaterialType2_2,

                    PackageNum2_2 = request.PackageNum2_2,
                    PpPcfPartNum2_2 = request.PpPcfPartNum2_2,
                    PpPcfBatchNum2_2 = request.PpPcfBatchNum2_2,
                    PpPcfExpire2_2 = request.PpPcfExpire2_2,
                    PostponedMaterial2_2 = request.PostponedMaterial2_2,

                    //满本结构
                    BookBuildupStructure = request.BookBuildupStructure,

                    PlateNum = Convert.ToInt32(request.PlateNum),
                    PanelQuan = Convert.ToInt32(request.PanelQuan),
                    SecionQuan = Convert.ToInt32(request.SecionQuan),
                    AlphaBoardStayTime = int.Parse(request.AlphaBoardStayTime),

                    StopperQuality = request.StopperQuality,
                    PerpregSurfaceQuality = request.StopperQuality,
                    PcsKraftQuality = request.StopperQuality,
                    InnerCoreQuality = request.StopperQuality,
                    CopperFoilQuality = request.CopperFoilQuality,
                    SteelPlateQuality = request.SteelPlateQuality,

                    AbnormalSteelPlateQuantity = int.Parse(request.AbnormalSteelPlateQuantity),
                    Remark = request.Remark,
                    //流程卡时间
                    TravellerDate = Convert.ToDateTime(travellerDate),
                    //材料时间
                    //MaterialDate =
                    WatchmanStatus = (int)WatchmanStatus.未使用,
                    WatchmanBy = null,
                    DeleteStatus = (int)DeleteStatus.未删除,
                    UseStatus = (int)UseStatus.未使用,
                    BookNum = request.BookNum,
                    Ip = Ip,
                    CreatedBy = user.Id,
                    CreatedDate = DateTime.Now
                };

                if(!string.IsNullOrEmpty(request.MaterialDate))
                {
                    try
                    {
                        iqs.MaterialDate = Convert.ToDateTime(request.MaterialDate);
                    }
                    catch(Exception ex)
                    {
                        iqs.MaterialDate = null;
                    }
                }
                else
                {
                    iqs.MaterialDate = null;
                }
                
                if(!string.IsNullOrEmpty(request.ContainerCode))
                {
                    iqs.ContainerCode = request.ContainerCode;
                }
                #endregion

                #region 两分钟验证
                //执行查询
                var model = _db.DbConnection.Query<IQS>("SELECT CreatedDate FROM iqs WHERE MachineCode=@MachineCode ORDER BY Id DESC LIMIT 0,1", new { MachineCode  = iqs.MachineCode}).FirstOrDefault();
                if (model != null)
                {
                    //时间差
                    var ts = DateTime.Now - model.CreatedDate;
                    //小于2分钟禁止保存
                    if (ts.TotalMinutes < 2)
                    {
                        throw new Exception("保存时间间隔必须大于2分钟.");
                    }
                }
                #endregion

                var id = (int)_db.DbConnection.Insert<IQS>(iqs);
                if (id <= 0)
                {
                    throw new Exception("写入失败.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return Json(response);

        }
        #endregion

        #region 缓存配置
        /// <summary>
        /// 获取配置
        /// </summary>
        public List<Config> GetConfig()
        {
            var key = "config";

            if (MemoryCacheUtil.Exists(key))
            {
                return MemoryCacheUtil.Get<List<Config>>(key);
            }
            else
            {
                //配置
                var configs = new List<Config>();

                #region Expire
                //当前时间
                var currentDataTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //查询
                var expireQuerySql = string.Format("select Id,Type,PartNo,LotNo,Cycle,FieldType,Value,Status from config where Expire>='{0}' AND Status=1", currentDataTime);
                //执行查询
                configs = _db.DbConnection.Query<Config>(expireQuerySql).ToList();
                #endregion

                #region Null
                //查询查询
                var nullQuerySql = "select Id,Type,PartNo,LotNo,Cycle,FieldType,Value,Status from config where Expire IS NULL AND Status=1";
                //执行查询
                var nullConfigs = _db.DbConnection.Query<Config>(nullQuerySql).ToList();
                if (nullConfigs != null && nullConfigs.Any())
                {
                    nullConfigs.ForEach(item => {
                        configs.Add(item);
                    });
                }
                #endregion

                MemoryCacheUtil.Set(key, configs, 10);

                return configs;
            }
        }

        /// <summary>
        /// 获取配置
        /// </summary>
        /// <returns></returns>
        public List<Dictionary> GetDictionary()
        {
            var key = "dictionary";

            if (MemoryCacheUtil.Exists(key))
            {
                return MemoryCacheUtil.Get<List<Dictionary>>(key);
            }
            else
            {
                //查询查询
                var dictionaryQuerySql = "select Id,Type,Name,Value,Status,DisplayOrder,CreatedDate from dictionary where Status=1";
                //执行查询
                var dictionarys = _db.DbConnection.Query<Dictionary>(dictionaryQuerySql).ToList();
                if(dictionarys!=null && dictionarys.Any())
                {
                    MemoryCacheUtil.Set(key, dictionarys, 120);
                }

                return dictionarys;
            }
        }
        #endregion

        #region 清除缓存
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public IActionResult Cache()
        {
            MemoryCacheUtil.Remove("config");
            MemoryCacheUtil.Remove("dictionary");
            return Content("清除缓存成功.");
        }
        #endregion
    }
}